Count()

count({ q?: {} })

The count() method in noonjs retrieves the total number of documents in a collection that match the given filter. This method is useful when you need to determine the size of a dataset without retrieving all documents, making it efficient for analytics, pagination, or conditional operations.

It retrieves the total number of documents in a collection.
const result = await client.collection("todos").count();
console.log(result)

// result
// { total: 2 }

Query with Condition

It retrieves the total number of done todos in a collection.
const todos = await client.collection("todos").count({ q: { done: { $exists: true } } });
            
// result
// { total: 1 }
Edit this page on Github
© 2025 kav3.com. Crafted with and dedication.