Using the $pull operator to remove an object via a nested field from an array in DocumentDB?

34 Views Asked by At

I have one entry in my Data collection and is as follows:

{
    "data": [
        {
            "key1": {
                "name": "test"
            }
        },
        {
            "key1": {
                "name": "test2"
            }
        }
    ]
}

I would like to remove the object where key1.name: 'test2' from the data array.

I have tried the following:

db.Data.updateOne({}, { $pull: { 'data': { 'key1.name': 'test2' } } })

This works fine in a container instance of mongodb (latest).

But in a DocumentDB with engine version 5.0, it does not work and returns MongoServerError: Dotted field name is not valid for storage.

Is there any way for me to use the $pull operator in a DocumentDB where I'm targeting an object via a nested field?

0

There are 0 best solutions below