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

Make the tests server handle upserts properly #216

Closed
denis-zhdanov opened this issue Feb 23, 2023 · 2 comments
Closed

Make the tests server handle upserts properly #216

denis-zhdanov opened this issue Feb 23, 2023 · 2 comments

Comments

@denis-zhdanov
Copy link

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

@bwaldvogel
Copy link
Owner

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

@bwaldvogel
Copy link
Owner

The fix is available via v1.44.0.

rgruber1 pushed a commit to rgruber1/mongo-java-server that referenced this issue Mar 13, 2024
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