retrieving all records(documents) of Couchbase

杀马特。学长 韩版系。学妹 提交于 2019-12-24 01:53:50

问题


I am using node.js and looking for a way to get all documents of a specific bucket of couchbase. Is there any solution without having a loop and incremental index ? I know I can make an atomic key and later on using it via a loop to retrieve all data.But I need a function which returns all documents. Is there any function which 'at least' return me the number of documents already exist in bucket?


回答1:


I've had this question before me as well, as per Couchbase engineering team its not possible without having a view. So I ended up having a naming convention for a view that should be present in every bucket that I want to have list of ALL keys.

I call it "Keys" and my map function like this:

function (doc, meta) {
  emit(meta.id, null);
}

So then on my client I can iterate over all the documents in the bucket...since I know all the keys.

Another alternative is to use N1QL to get all the keys. THis is a new query language introduced in Couchbase 3. So you can write a query like this to return all documents keys:

SELECT META().id AS id 
FROM your_bucket_name

Or you can return all documents themselves:

SELECT * 
FROM your_bucket_name

Check Node.js and N1QL for additional information.



来源:https://stackoverflow.com/questions/26017989/retrieving-all-recordsdocuments-of-couchbase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!