DAB
Search…
find
1
find(params)
Copied!

Arguments

Params (required)

As parameter, pass the following object:
  • collection: Required, the name of collection you want to work with.
  • query: query in MongoDB-style query syntax. Optional, defaults to: {} (match all).
  • sort: sort order, as a string, array or object. Optional. Example:
    1
    { name: 1, age: -1 }
    Copied!
  • limit: max. number of documents in one page. Optional, defaults to 25. Overridable through options object.
  • page: page number, starting from 1. Optional, defaults to 1
Example:
1
{
2
collection: 'users',
3
query: {
4
age: { $gt: 20 }
5
},
6
page: 1,
7
limit: 25
8
}
Copied!

Response

Result

It should return an object like below:
1
{
2
success: true,
3
total: 120,
4
data: [
5
{ _id: 'james-bond', name: 'James Bond', age: 20 },
6
{ _id: 'jack-bauer', name: 'Jack Bauer', age: 20 },
7
{ _id: 'jason-bourne', name: 'Jason Bourne', age: 20 },
8
...
9
]
10
}
Copied!
If no document found, it should NOT yield error. Instead, it sould return an empty data with total = 0.
total is the total number of documents found matched with your query. Optional, but strongly recommended to return this value.

Error

In case of error, it'll yield a normal Node error object you can catch through promise easily.
Last modified 3yr ago