Advertisement
tabvn

Loopback Mongodb Query

Jul 13th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  var GroupCollection = User.getDataSource().connector.collection(User.app.models.group.modelName);
  2.           GroupCollection.aggregate([
  3.             {$match: {status: true}},
  4.             {$sort: {updatedAt: 1}},
  5.             {
  6.               $lookup: {localField: "_id", from: "member", foreignField: "groupId", as: "members"}
  7.             },
  8.             {
  9.               $group: {
  10.                 _id: "$_id",
  11.                 members: {$addToSet: "$members.userId"}
  12.               }
  13.             },
  14.             {
  15.               $project: {
  16.                 _id: 1,
  17.                 title: 1,
  18.                 members: {$arrayElemAt: ["$members", 0]}
  19.               }
  20.             },
  21.             {
  22.               $match: {
  23.                 $and: [
  24.                   {members: {$all: paticipants}},
  25.                   {members: {$size: paticipants.length}}
  26.                 ]
  27.               }
  28.             }
  29.           ], function (err, result) {
  30.             console.log("Found result", paticipants, result);
  31.            
  32.  
  33.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement