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();
1const query = Customer.find().sort({ name: 1 }).limit(1);
2query.getOptions(); // { sort: { name: 1 }, limit: 1 }
1router.post('/travellers',
2 passport.authenticate('jwt', { "session": false }), function(req, res, next) {
3 var pickup_location = req.body.pickup_location;
4 var delivery_location = req.body.delivery_location;
5 var date = req.body.date;
6 var sender = req.user._id;
7 var locals = {
8 travellers: [],
9 senders: []
10 };
11
12 async.series([
13 // Load travels first
14 function(callback) {
15 Travel.find({ "date": date }, function (err, travels) {
16 if (err) return callback(err);
17 locals.travels = travels;
18 callback();
19 });
20 },
21 // Load users (won't be called before task 1's "task callback" has been called)
22 function(callback) {
23 async.forEach(locals.travels, function (travel, callback) {
24 User.findById(travel.traveller, function (err, user) {
25 if (err) return callback(err);
26 data = {
27 "name": user.name,
28 "email": user.email,
29 "phone": user.phone,
30 "image_url": user.image_url,
31 "type": "traveller"
32 };
33 console.log(data);
34 local.travellers.push(data);
35 callback();
36 });
37 }, function (err) {
38 if (err) return callback(err);
39 callback();
40 });
41 }
42 ], function(err) { /* This function gets called after
43 the two tasks have called their "task callbacks" */
44 if (err) return next(err);
45 //Here locals will be populated with `travellers` and `senders`
46 //Just like in the previous example
47 console.log(locals);
48 console.log(locals.travellers);
49 res.json(locals.travellers);
50 });
51});