1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| User.countDocuments(filters).exec((count_error, count) => {}) User.estimatedDocumentCount()
User.find(function(err, res){ console.log(res) })
User.find({}, 'age'); User.find({}, {age: 1}); User.find({}, '-age'); User.find({}, {age: 0});
User.findById('abc');
User.findOne({ username: 'haofly', isActive: true, name: {$regex: new RegExp(keyword, "i")}}, name: { last: "hao" } 'name.last': 'hao', id: { $in: ["123", "321"], $nin: ["123"], $eq: 12, $ne: 12, $gt: 12, $gte: 12, $lt: 12, $lte: 12, }, $and: [{expression1}, {expression2}], $nor: [{expression1}, {expression2}], $or: [{expression1}, {expression2}], age: { $not: { $gt: 12 } }, books: { $all: ["abc", "def"] } ages: { $elemMatch: { $gt: 12, $lt: 15 } } 'ages.1': {$gt: 12} }) .offset(0) .limit(10) .sort('-created_at') .select: ["username", "email"] .select({"username" :1, "email": -1}) .populate(['father']) .populate({ path: 'friends', select: 'username', select: ['username', '-email'], match: { username: { $regex: '.*' + keyword + '.*', $regex: new RegExp(keyword, "i"), } }, populate: [{ path: 'inviteBy', select: ['username'] }] }) .then(user => { console.log(user) }) .catch((err) => { console.log(err) })
let query = User.find({}).where('age').gt(12).select('name age -_id') query.exec((err, result) => {})
query.then( (res) => {console.log(res)} (err) => {console.log(err)} );
|