Skip to content

_id not used for upsert when part of $and-filter #208

Description

@vandmo

The following code illustrates the issue.

            // This works as expected
            // Creates: {"_id": "as_expected", "value": 100}
            collection
                    .findOneAndUpdate(
                            BsonDocument.parse("{\"_id\": \"as_expected\"}"),
                            BsonDocument.parse("{\"$set\": {\"value\": 100}}"),
                            new FindOneAndUpdateOptions().upsert(true));

            // This generates an identifier instead of using the one in the $and-list
            // Creates: {"_id": {"$oid": "f6a40f2c1855632c12f51c59"}, "value": 200}
            collection
                    .findOneAndUpdate(
                            BsonDocument.parse("{\"$and\": [{\"_id\": \"this_goes_gone\"}]}"),
                            BsonDocument.parse("{\"$set\": {\"value\": 200}}"),
                            new FindOneAndUpdateOptions().upsert(true));

The same request towards the official MonoDB would find and use the _id supplied in the query/filter.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions