-
Notifications
You must be signed in to change notification settings - Fork 376
Finding items
L8D edited this page Oct 10, 2014
·
13 revisions
Find records with matching criteria, can be chained (see below):
Person.find({status:'active'}, function(err, results) {
...
});
You can limit your results as well. This limits our results to 10
Person.find({status:'active'}, 10, function(err,results) {
...
});
Person.all
is an alias to Person.find
Find record by primary key.
Person.get(1,function(err,person) {
...
});
Find one record with similar syntax to find.
Person.one( function(err, person) {
...
});
Get the number of matching records.
Person.count({status:'active'}, function(err,activePeopleCount) {
// activePeopleCount is integer
...
});
Test a record matching your conditions exists.
Person.exists({id:1, status:'active'}, function(err, personIsActive) {
// ...
});
All comma seperated key/values are AND'd together in the query. You may prefix a set of conditions with logical operators.
Person.find({or:[{col1: 1}, {col2: 2}]}, function(err, res) {
// res is Person where col1 == 1 or col2 == 2
});