Select all documents along with their IDs and restructure the result

Hi, my question is how to select all documents along with their IDs and restructure the result?

Example Data

Say I have a bucket example, and it has 2 documents:

// document ID: 1
{
  "content": "this is the 1st document"
}

// document ID: 2
{
  "content": "this is the 2nd document"
}

Question

By running the following query:

SELECT meta(`example`).id, * FROM `example`

I can get:

[
  {
    "id": "1",
    "example": {
      "content": "this is the 1st document"
    }
  },
  {
    "id": "2",
    "example": {
      "content": "this is the 2nd document"
    }
  }
]

1. Is it possible to make the result look like this:

[
  {
    "id": "1",
    "content": "this is the 1st document"
  },
  {
    "id": "2",
    "content": "this is the 2nd document"
  }
]

2. or even this:

[
  {
    "1": {
      "content": "this is the 1st document"
    },
    "2": {
      "content": "this is the 2nd document"
    }
  }  
]

Many thanks!!!

1 Like
SELECT META(`example`).id,`example`.* FROM `example`

SELECT {META(`example`).id:`example`}.* FROM `example`

FYI

2 Likes

Very helpful!!! Thank you!