Skip to content

replaceOne not upserting? #43

@skedwards88

Description

@skedwards88

From this Slack conversation

When I execute the following code, I would expect upsertion. However, it looks like no documents are replaced or upserted.

        Filter filter = Filters.eq("_id", "Idontexist");
        Document newDocument = new Document()
            .append("isCheckedOut", false)
            .append("borrower", "Brook Reed");
        ReplaceOneOptions options = new ReplaceOneOptions().upsert(true);
        UpdateResult result = collection.replaceOne(filter, newDocument, options);
        System.out.println(result.getMatchedCount());
        System.out.println(result.getModifiedCount());
        System.out.println(result.getUpsertedId());

prints

0
0
null

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions