Read multiple documents

To read multiple documents in a collection, you'll need a reference to that collection.

const ref = adamite().database().collection("projects");

Once you have a reference, you can use the get method to fetch a snapshot of that collection, which will contain snapshots for all of the documents in that collection.

const snap = await ref.get();
const docs = snap.docs;

Filter documents by properties

When building a reference to a collection, you can add queries to the reference which can limit the data returned by the reference. To add a query, use the where method on a collection reference.

const ref = 
  adamite()
    .database()
    .collection("projects")
    .where("name", "==", "Project Name");

You can add multiple queries by calling where multiple times. These queries are applied as AND queries. OR queries are not possible with the SDK at this time.

Available filter options

The following values can be used for the comparator (the second parameter) of the call to where...

Value

Description

==

Finds documents where field is equal to value.

!=

Finds documents where field is not equal to value.

>

Finds documents where field is greater than value.

<

Finds documents where field is less than value.

>=

Finds documents where field is greater than or equal to value.

<=

Finds documents where field is less than or equal to value.

array-contains

Finds documents where an array, field , contains value.

array-not-contains

Finds documents where an array, field, does not contain value.

matches

Finds documents where field matches regex expression value.

not-matches

Finds documents where field does not match regex expression value.

Order returned documents

You can change the order documents are returned to you in a snapshot by calling the orderBy function on the reference.

const ref = 
  adamite()
    .database()
    .collection("projects")
    .orderBy("name", "asc"); // or "desc"

Limit the number of documents returned

By default, only the first 1000 documents will be returned in a snapshot. You can change this by calling the limit function on the reference.

const ref = 
  adamite()
    .database()
    .collection("projects")
    .limit(10);

By default, there is no server-enforced upper limit for the number of documents that can be returned in a query. Performance may suffer with large limit values.

Last updated