Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$push with updateObject does not create the array if the fields does not exist #384

Closed
nkemcels opened this issue Oct 3, 2023 · 1 comment
Labels

Comments

@nkemcels
Copy link

nkemcels commented Oct 3, 2023

Hello @kofrasa, when I run this query on MongoDB, it works

// input
// ---------
[
  {
    _id: "651842a8b50c196f074197ce",
    name: "Celsoppe"
  }
]

// query
// ----------
db.collection.update({},
{
  $push: {
    "attributes.scores.bar": {
      a: 1
    }
  }
})

// result/output
// -----------
[
  {
    "_id": "651842a8b50c196f074197ce",
    "attributes": {
      "scores": {
        "bar": [
          {
            "a": 1
          }
        ]
      }
    },
    "name": "Celsoppe"
  }
]

You can see that the attributes.scores.bar array doesn't exist but gets created with the $push operator. However, with mingo, that array must exist before the $push can go through.

@kofrasa kofrasa added the bug label Oct 3, 2023
@kofrasa
Copy link
Owner

kofrasa commented Oct 3, 2023

Thanks for identifying this bug. The object graph is not built in realtime for the $push operator and many others so the full graph must exist. Will look into it.

@kofrasa kofrasa closed this as completed in dd81451 Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants