I’m trying to SELECT all the fields in the bucket using GET request http://node:8093/query/service?statement=select%20*%20from%20mybucket in N1QL, but the returned JSON does not include the document id, and the blob attachment. What type of query will I used to include them in the result.
In N1QL you use meta().id
to refer to the document ID. (See the docs.)
Mobile documents have some other metadata that doesn’t usually appear in the document in Server; that includes attachments, and the revision ID and so forth. I don’t know how you access those from N1QL. Hopefully someone else does. What about the attachments do you need to use in a query?
Documentation on accessing other SG metadata is here.
I was hoping to load it in a ImageView, the returned JSON looks like this.
"results": [
{
"image": {
"@type": "blob",
"content_type": "image/jpeg",
"digest": "sha1-0kHlb8YqV0fZ4HG6dUreJSIGIXI=",
"length": 230187
}
}
]
The document JSON only holds the metadata of the image, since JSON can’t efficiently store binary data.
To get the data itself you need to know the attachment name according to Sync Gateway, which is the key in the _attachments
dictionary. (Sorry, I don’t know how you access that from N1QL.) Once you have the key you send a GET /dbname/docid/key
request to SG.
Got this, thank you @jens very helpful as usual. I also add blob_%2F
before the image name. Something like this
node/dbname/docid/blob_%2Fimagename