Visitar URL original
Make the tests server handle upserts properly · Issue #216 · bwaldvogel/mongo-java-server · GitHub
Skip to content

Make the tests server handle upserts properly #216

Closed

Description

@denis-zhdanov

Problem

Consider the following client code:

import com.mongodb.client.model.Filters
import com.mongodb.client.MongoClient

private val client: MongoClient = ...

...
        val data = mapOf("key1" to "value1", "key2" to "value2")
        val filter = Filters.and(data.map {
            Filters.eq(it.key, it.value)
        })
        client.getDatabase(db).getCollection(collection).updateOne(
            filter,
            Updates.set("dummy", "dummy"),
            UpdateOptions().upsert(true)
        )

When this is executed on an empty mongo java server collection, the expectation is to have a document with fields key1, key2 and dummy. However, key1 and key2 are not inserted even though that is a legitimate mongo client api usage.

The reason is that de.bwaldvogel.mongo.backend.AbstractMongoCollection.convertSelectorToDocument() has the following code:

            if (key.startsWith("$")) {
                continue;
            }

Task

Fix the problem

Activity

  1. bwaldvogel commented on Jun 2, 2023

    @bwaldvogel
    Owner

    Thanks for reporting this issue. It should be fixed with f20f3cb

  2. bwaldvogel commented on Jun 25, 2023

    @bwaldvogel
    Owner

    The fix is available via v1.44.0.

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