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();
1// find all documents
2await MyModel.find({});
3
4// find all documents named john and at least 18
5await MyModel.find({ name: 'john', age: { $gte: 18 } }).exec();
6
7// executes, passing results to callback
8MyModel.find({ name: 'john', age: { $gte: 18 }}, function (err, docs) {});
9
10// executes, name LIKE john and only selecting the "name" and "friends" fields
11await MyModel.find({ name: /john/i }, 'name friends').exec();
12
13// passing options
14await MyModel.find({ name: /john/i }, null, { skip: 10 }).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 };