Luis Costa
Luis Costa

Reputation: 330

Mongo query multiple levels of nested document

I have a mongodb collection that has 'nested' documents. For example, a document can have the following structure:

{
    "condition": {
        "parameter": {
            "type": "person"
        }
    }
}

as well as the next one:

{
    "condition": {
        "conditions": [
            {
                "conditions": [
                    {
                        "parameter": {
                            "type": "A"
                        }
                    },
                    {
                        "parameter": {
                            "type": "B"
                        }
                    }
                ]
            },
            {
                "parameter": {
                    "type": "C"
                }
            }
        ]
    }
}

Meaning, each condition sub-document can have multiple conditions within itself.

Now, I'd want to make a 'recursive' query on the type field of each condition, something like ('..' representing the recursion):

{
    "$or": [
        {"condition.type": "person"},
        {"condition..conditions.type": "person"}
    ]
}

Is there any way to do this in Mongo?

Upvotes: 3

Views: 518

Answers (0)

Related Questions