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

Document replace not supported #227

Closed
madmaxpt opened this issue Feb 28, 2024 · 2 comments
Closed

Document replace not supported #227

madmaxpt opened this issue Feb 28, 2024 · 2 comments

Comments

@madmaxpt
Copy link

Running the following code :

try(var client = MongoClients.create(connectString))
{
    var collection = client.getDatabase("testDatabase").getCollection("testCollection");
    var replaceOptions = new ReplaceOptions().upsert(true);
    System.out.println(collection.bulkWrite(
            Collections.singletonList(new ReplaceOneModel<>(Filters.eq(new BsonString("myId")),
                    Document.parse("{\"value\": \"test\"}"), replaceOptions))
    ));
    System.out.println(collection.bulkWrite(
            Collections.singletonList(new ReplaceOneModel<>(Filters.eq(new BsonString("myId")),
                    Document.parse("{}"), replaceOptions))
    ));
}

Displays the following output :

AcknowledgedBulkWriteResult{insertedCount=0, matchedCount=0, removedCount=0, modifiedCount=0, upserts=[BulkWriteUpsert{index=0, id=BsonString{value='myId'}}], inserts=[]}
AcknowledgedBulkWriteResult{insertedCount=0, matchedCount=1, removedCount=0, modifiedCount=0, upserts=[], inserts=[]}

The document is matched but not modified.

Running it against a MongoDB server, we get the following output :

AcknowledgedBulkWriteResult{insertedCount=0, matchedCount=0, removedCount=0, modifiedCount=0, upserts=[BulkWriteUpsert{index=0, id=BsonString{value='myId'}}], inserts=[]}
AcknowledgedBulkWriteResult{insertedCount=0, matchedCount=1, removedCount=0, modifiedCount=1, upserts=[], inserts=[]}

And the document is modified as expected.

Using mongo-java-server version 1.44.0 and mongodb-driver-sync version 4.11.1

@bwaldvogel
Copy link
Owner

Fixed via #229

@bwaldvogel
Copy link
Owner

Fix is released in version 1.45.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants