Skip to content

{$exists: false} not working for nested fields in $pull statement #8166

@JonathanCallewaert

Description

@JonathanCallewaert

I have a collection documents with a document that looks like this:

{
    "_id" : ObjectId("5d7ddedf92264a43ceee9f48"),
    "name" : "test123",
    "predictedEntityValues" : [ 
        {
            "status" : "DONE",
            "values" : [ 
                {
                    "text" : "123"
                }
            ]
        }
    ]
}

I have the following query where documentIds = [ ObjectId("5d7ddedf92264a43ceee9f48") ]

await models.documents
    .updateMany(
      { _id: { $in: documentIds } },
      {
        $pull: {
          predictedEntityValues: { 'values.0.coords': { $exists: false } },
        },
      }
    )

The above query should should remove the value in the array 'predictedEntityValues', but it doesn't.
My query is correct because when I execute it into the mongo shell, it works.

I turned on debug mode, and I saw that the library parsed my query to this query:

Mongoose: documents.updateMany({ _id: { '$in': [ ObjectId("5d7ddedf92264a43ceee9f48") ] } }, { '$setOnInsert': { createdAt: new Date("Sun, 15 Sep 2019 06:42:51 GMT") }, '$set': { updatedAt: new Date("Sun, 15 Sep 2019 06:42:51 GMT") }, 
'$pull': {  predictedEntityValues: { 'values.0.coords': {} } } }, {})

As you can see, it removes the $exists false in the parsed query: { predictedEntityValues: { 'values.0.coords': {} } } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions