Guest User

Untitled

a guest
Oct 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. // doesn't work ... of course ...
  2.  
  3. model.find({
  4. '_id' : [
  5. '4ed3ede8844f0f351100000c',
  6. '4ed3f117a844e0471100000d',
  7. '4ed3f18132f50c491100000e'
  8. ]
  9. }, function(err, docs){
  10. console.log(docs);
  11. });
  12.  
  13. model.find({
  14. '_id': { $in: [
  15. mongoose.Types.ObjectId('4ed3ede8844f0f351100000c'),
  16. mongoose.Types.ObjectId('4ed3f117a844e0471100000d'),
  17. mongoose.Types.ObjectId('4ed3f18132f50c491100000e')
  18. ]}
  19. }, function(err, docs){
  20. console.log(docs);
  21. });
  22.  
  23. // this will complement the list with userName and userPhotoUrl based on userId field in each item
  24. augmentUserInfo = function(list, callback){
  25. var userIds = [];
  26. var users = []; // shortcut to find them faster afterwards
  27. for (l in list) { // first build the search array
  28. var o = list[l];
  29. if (o.userId) {
  30. userIds.push( new mongoose.Types.ObjectId( o.userId ) ); // for the Mongo query
  31. users[o.userId] = o; // to find the user quickly afterwards
  32. }
  33. }
  34. db.collection("users").find( {_id: {$in: userIds}} ).each(function(err, user) {
  35. if (err) callback( err, list);
  36. else {
  37. if (user && user._id) {
  38. users[user._id].userName = user.fName;
  39. users[user._id].userPhotoUrl = user.userPhotoUrl;
  40. } else { // end of list
  41. callback( null, list );
  42. }
  43. }
  44. });
  45. }
  46.  
  47. let arr = _categories.map(ele => new mongoose.Types.ObjectId(ele.id));
  48.  
  49. Item.find({ vendorId: mongoose.Types.ObjectId(_vendorId) , status:'Active'})
  50. .where('category')
  51. .in(arr)
  52. .exec();
Add Comment
Please, Sign In to add comment