Question

I have those documents:

{
    "result": "ok",
    "variants": [
        {
            "state": {
                "state1": false,
                "state2": false
            }
        },
        {
            "state": {
                "state1": false,
                "state2": false
            }
        }

    ]
}

{
    "result": "ok",
    "variants": [
        {
            "state": {
                "state1": false,
                "state2": false
            }
        },
        {
            "state": {
                "state1": false,
                "state2": true
            }
        }

    ]
}


{
    "result": "not_ok",
    "variants": [
        {
            "state": {
                "state1": true,
                "state2": false
            }
        },
        {
            "state": {
                "state1": true,
                "state2": false
            }
        }

    ]
}


{
    "result": "not_ok",
    "variants": [
        {
            "state": {
                "state1": true,
                "state2": false
            }
        },
        {
            "state": {
                "state1": false,
                "state2": true
            }
        }

    ]
}

and i nead to find those one where at least one variant in the document has state1: false and state2: false. I have tried this find:

{
    "variants.state.state1": false,
    "variants.state.state2": false
}

But it gives me the documents where one of the variants has state1: false and one of the variants has state2: false. It applies the where to the subdocuments individually and not both filters to one subdocument.

Was it helpful?

Solution

this is the answer:

{
    "variants.state": { "$elemMatch" : {"state1" : false, "state2" : false } }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top