Skip to content

Make the tests server handle upserts properly #216

@denis-zhdanov

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

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