Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // doesn't work ... of course ...
- model.find({
- '_id' : [
- '4ed3ede8844f0f351100000c',
- '4ed3f117a844e0471100000d',
- '4ed3f18132f50c491100000e'
- ]
- }, function(err, docs){
- console.log(docs);
- });
- model.find({
- '_id': { $in: [
- mongoose.Types.ObjectId('4ed3ede8844f0f351100000c'),
- mongoose.Types.ObjectId('4ed3f117a844e0471100000d'),
- mongoose.Types.ObjectId('4ed3f18132f50c491100000e')
- ]}
- }, function(err, docs){
- console.log(docs);
- });
- // this will complement the list with userName and userPhotoUrl based on userId field in each item
- augmentUserInfo = function(list, callback){
- var userIds = [];
- var users = []; // shortcut to find them faster afterwards
- for (l in list) { // first build the search array
- var o = list[l];
- if (o.userId) {
- userIds.push( new mongoose.Types.ObjectId( o.userId ) ); // for the Mongo query
- users[o.userId] = o; // to find the user quickly afterwards
- }
- }
- db.collection("users").find( {_id: {$in: userIds}} ).each(function(err, user) {
- if (err) callback( err, list);
- else {
- if (user && user._id) {
- users[user._id].userName = user.fName;
- users[user._id].userPhotoUrl = user.userPhotoUrl;
- } else { // end of list
- callback( null, list );
- }
- }
- });
- }
- let arr = _categories.map(ele => new mongoose.Types.ObjectId(ele.id));
- Item.find({ vendorId: mongoose.Types.ObjectId(_vendorId) , status:'Active'})
- .where('category')
- .in(arr)
- .exec();
Add Comment
Please, Sign In to add comment