Reputation: 703
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?
Upvotes: 3
Views: 2338
Reputation: 533
There is now a range scan feature to retrieve all documents or all ids in a collection. See Couchbase retrieving all documents from all collections in scope
Upvotes: 0
Reputation: 2848
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.
Upvotes: 2