0

I have a document with structure

[{
    "_id": "ECF",
    "values": [
        {
            "name": 'cc1',
            "value": 112
        },
        {
            "name": 'dv2',
            "value": 34234
        }
    ]
},
    , {
    "_id": "DQE",
    "values": [
        {
            "name": 'ce53',
            "value": 1124,
        },
        {
            "name": 'asdc',
            "value": 332,
        }
    ]
}]

Values have a really huge number of objects, so I need to filter them. So the question is how could I get filtered values?

I did query collection.find({"_id":"DQE", "values.name":{$in:['asdc','ce53']}}, {"values.$":1})

But it returns only first matched value object. Thank you for help :)

1 Answers1

0

If you are using the 3.2 version, you can use $filter but with aggregation, not find.

collection.aggregate({"_id":"DQE", items: {
            $filter: {
               input: "$values",
               cond: { $in: [ "$$values.name", ['asdc','ce53'] ] }
            }
         }}
Notrius
  • 315
  • 2
  • 8