1Post.find({}).sort('test').exec(function(err, docs) { ... });
2Post.find({}).sort([['date', -1]]).exec(function(err, docs) { ... });
3Post.find({}).sort({test: 1}).exec(function(err, docs) { ... });
4Post.find({}, null, {sort: {date: 1}}, function(err, docs) { ... });
1MyModel.findOne().lean().exec(function(err, doc) {
2 doc.addedProperty = 'foobar';
3 res.json(doc);
4});
1// Find the adventure with the given `id`, or `null` if not found
2await Adventure.findById(id).exec();
3
4// using callback
5Adventure.findById(id, function (err, adventure) {});
6
7// select only the adventures name and length
8await Adventure.findById(id, 'name length').exec();
1exports.generateList = function (req, res) {
2 subcategories
3 .find({})//grabs all subcategoris
4 .where('categoryId').ne([])//filter out the ones that don't have a category
5 .populate('categoryId')
6 .where('active').equals(true)
7 .where('display').equals(true)
8 .where('categoryId.active').equals(true)
9 .where('display').in('categoryId').equals(true)
10 .exec(function (err, data) {
11 if (err) {
12 console.log(err);
13 console.log('error returned');
14 res.send(500, { error: 'Failed insert' });
15 }
16
17 if (!data) {
18 res.send(403, { error: 'Authentication Failed' });
19 }
20
21 res.send(200, data);
22 console.log('success generate List');
23 });
24 };
1// sort by "field" ascending and "test" descending
2query.sort({ field: 'asc', test: -1 });
3
4// equivalent
5query.sort('field -test');