Answers for "mongodb aggregate match in array"

1

MongoDB Aggregation Lookup Match Array

db.users.aggregate([
  {"$match":{"_id":ObjectId(..)}},
  {"$lookup":{
    "from":"groups",
    "let":{"_id":"$_id"},
    "pipeline":[
      {"$match":{"$expr":{"$in":["$$_id","$members"]}}},
      {"$unwind":"$members"},
      {"$match":{"$expr":{"$eq":["$$_id","$members"]}}}
    ],
    "as":"members"
  }}
])
Posted by: Guest on June-01-2021
1

mongodb aggregate lookup array of objects

db.getCollection('widgets').aggregate([
    { $unwind: '$info' },
    {
        $lookup: {
            from: 'icons',
            localField: 'info.iconId',
            foreignField: '_id',
            as: 'info.icon'
        }
    },
    { $unwind: '$info.icon' },
    {
        $group: {
            _id: '$_id',
            root: { $mergeObjects: '$$ROOT' },
            info: { $push: '$info' }
        }
    },
    {
        $replaceRoot: {
            newRoot: {
                $mergeObjects: ['$root', '$$ROOT']
            }
        }
    },
    {
        $project: {
            root: 0
        }
    }
]);
Posted by: Guest on August-29-2020
0

mongodb match multiple fields

$match:
{
	$and: [
    {'ExtraFields.value': {$in: ["A52A2A"]}}, 
    {'ExtraFields.fieldID': ObjectId("5535627631efa0843554b0ea")}
    ]
}
Posted by: Guest on July-01-2020

Code answers related to "mongodb aggregate match in array"

Browse Popular Code Answers by Language