Get documents with a specific key using all-docs query

Hi all,

in the queries Guide section I read:

…You use an all-docs query to find all the documents in the database, or the documents with keys in a specific range, or even the documents with a specific set of keys.

So this sounds like I can get a set of documents without creating a specific view. But… what is the document key? How do I define it? Is it a special document property?



The default behavior in Couchbase Lite is to assign a key automatically to a document. If you want to specify the ID, you can either add the _id property to your doc, or call the getDocument(docId) method. If the document with key docId does not exist, it will return a document with docId as key, but not persisted. You will have to add your data and then save the doc.

Hello @cabbi,

You can find the different ways to set the keys on the query (by range or passing in an array of keys) here

With the allDocs query, the key is always _id, so if you need to query on another key you’ll have to create a view to index documents by that other key.