0

I'm trying to update an object that is inside a multi nested array in Mongodb. I know that I cannot use the positional $ operator for multi nested arrays. So I'm trying to use arrayFilters instead.

Here is my query structure:

var objTest = {
    name: 'blah',
    color: 'blablah'
}

SomeModel.updateOne(
    {
        an_id: anId,
        "an_array.another_array.and_another_array.some_id": id,
    },
    {
        $set: {
            "an_array.$[element].another_array.$[another_element].and_another_array": objTest,
        },
    },
    {
        arrayFilters: [
            { "element.name": 'test' },
            { "another_element.id": 'test2' },
        ],
    }
)
.then((result) => {
    console.log("result ", result);
    resolve(result);
})
.catch((err) => {
    console.log("err is ", err);
    reject(err);
});

So as per the example, I'm trying to update the object that matches some_id in the and_another_array array. When I try this, I'm receiving the error The top-level field name must be an alphanumeric string beginning with a lowercase letter, found 'another_element'

I don't understand what I'm doing wrong here.

1 Answer 1

0

I was able to figure out what the issue was. For some reason, mongodb didn't like the in another_element. renaming it to anotherelement worked.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.