Can't $push to an array field in MongoDB

I’m trying to update a MongoDB document by adding a new item to an array field without overwriting the existing ones.

example:
I have a collection students and each student document contains an array of grades:
{
“_id”: “666abc1234567890abcdef12”,
“name”: “John Doe”,
“grades”: [
{ “subject”: “Math”, “score”: 95 }
]
}
Now I want to add a new grade, like:
{ “subject”: “Science”, “score”: 88 }

I thought I could use the MongoDB node (update) with:

  • Update Key: _id
  • Fields: grades
  • Value:
    {
    “$push”: {
    “grades”: {
    “$each”: [
    { “subject”: “Science”, “score”: 88 }
    ]
    }
    }
    }
    But this results in Mongodb storing $push as field, like this:
    {
    “_id”: “…”,
    “name”: “John Doe”,
    “grades”: {
    “$push”: {
    “grades”: {
    “$each”: [
    { “subject”: “Science”, “score”: 88 }
    ]
    }
    }
    }
    }

Information n8n setup

  • n8n version:1.99.1
  • Running n8n via Docker: