问题
I put some data to CouchBase 1.8.1,and get it successful.But I want to query its metadata,as expiration and att_reason(non-json or json).In some document,it list the metadata with json format,for example:
{
"_id" : "contact_475",
"_rev" : "1-AB9087AD0977F089",
"_bin" : "...",
"$flags" : 0,
"$expiration" : 0,
"name" : "Fred Bloggs",
}
How can I query item's metadata?
回答1:
As Pavel the most common way to access metadata in Couchbase (2.0) is using Views.
You can also use the internal TAP protocol : http://www.couchbase.com/wiki/display/couchbase/TAP+Protocol
Could you give us more information about your use case and why you need to access meta/expiration ? And why you cannot use views (that is the recommended way to do it)
Regards Tug
回答2:
The easiest way is issuing an HTTP request to:
http://serveraddress:8091/couchBase/default/contact_475
The response should contain an X-Couchbase-Meta
header with the metadata. More information is here: http://xmeblog.blogspot.co.il/2013/08/couchbase-how-to-retrieve-key.html
回答3:
If you want to see the meta data in a Couchbase query you can do something like this:
SELECT meta(b).* FROM bucket b
You can also see both meta data and all other data in a query by doing something like this:
SELECT meta(b).*, * FROM bucket b
回答4:
If you want to query only meta data using N1QL you could run below query, it will return all meta data about document :
select meta(bucket_name) from bucket_name
But if you want to get these information from Sync Gateway it will return to you by every GET request using REST API, the REST API also include some filtering above these meta data.
来源:https://stackoverflow.com/questions/13332816/how-to-query-items-metadata-from-couchbase