// 1,2,3,10 - список идентификаторов
db.collection.find({$where: "[1,2,3,10].filter(id => (this.articles.map(id => '' + id).indexOf(id) != -1)).length > 0"})
// 10 - ид записи
db.collection.find({$where: "this.articles.map(id => '' + id).indexOf(10) != -1"})
var shortLinks = Link.find().exec();
// ...
shortLinks.then(function(links){
// work with links
}, function(err){
// some error
});
// ...
var UserSchema = new Schema({
name: String,
email: {type: String, lowercase: true},
contracts: [{
type: Schema.Types.ObjectId,
ref: 'Contract'
}]
});
module.exports = mongoose.model('User', UserSchema);
// ...
User.findOne({
_id: userId
}, '-salt -hashedPassword')
.populate('contracts')
.exec(function(err, user) { // don't ever give out the password or salt
if (err) return next(err);
if (!user) return res.json(401);
// user.contracts.forEach(function(contract, index){ console.log(index, contract); });
res.json(user);
});