xxxxxxxxxx
/*
The $in operator selects the documents where the value of a
field equals any value in the specified array.
*/
-- Syntax : { field: { $in: [<value1>, <value2>, <valueN> ] } }
db.inventory.find( { quantity: { $in: [ 5, 15 ] } }, { _id: 0 } )
xxxxxxxxxx
db.inventory.find( {} )
MongoDB Shell
This operation corresponds to the following SQL statement:
SELECT * FROM inventory
xxxxxxxxxx
let userBuilds = [];
Wishlist.find({}, function (err, builds) {
if (err)
{
console.log("Cannot fetch wishlisted builds");
return res.redirect('back');
}
async.forEachOf(builds, function (build, key, callback) {
Builds.find({ name: build.name }, function (err, detailBuild) {
if (err)
{
console.log("Cannot fetch detail from wishlisted builds");
return res.redirect('back');
}
userBuilds.push(detailBuild[0]);
callback();
});
}, function (err) {
if (err)
{
console.log("Error in rendering page");
return res.redirect('back');
}
return res.render('wishlist', {
title: "Wishlist",
email: req.session.email ? req.session.email : undefined,
builds: userBuilds,
layout: false
});
});
});
xxxxxxxxxx
db.players.find( { $where: function() { return (hex_md5(this.name) == "9b53e667f30cd329dca1ec9e6a83e994")} } );
xxxxxxxxxx
UserModel.find() // find all users
.skip(100) // skip the first 100 items
.limit(10) // limit to 10 items
.sort({firstName: 1} // sort ascending by firstName
.select({firstName: true} // select firstName only
.exec() // execute the query
.then(docs => {
console.log(docs)
})
.catch(err => {
console.error(err)
})