问题描述
我正在使用node.js并正在寻找一种方法来获取特定存储空间的所有文档.有没有循环和增量索引的解决方案吗?我知道我可以创建一个原子键,然后通过循环使用它来检索所有数据,但是我需要一个返回所有文档的函数.是否有任何功能至少"返回存储桶中已经存在的文档数量?
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?
推荐答案
我也遇到了这个问题,根据Couchbase工程团队的说法,没有观点就不可能.因此,我最终有了一个视图的命名约定,该视图应该出现在我要具有所有键列表的每个存储桶中.
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.
另一种替代方法是使用 N1QL 来获取所有密钥.这是Couchbase 3中引入的新查询语言.因此,您可以编写如下查询以返回所有文档键:
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
检查 Node.js和N1QL ,以获取更多信息.
Check Node.js and N1QL for additional information.
这篇关于检索Couchbase的所有记录(文档)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!