https://kotlinlang.org logo
#kmongo
Title
# kmongo
a

André Martins

04/19/2022, 10:14 AM
Hello, I’m doing an
insertMany
query and trying to use an upsert although there is no InsertManyOption for upsert I came up with the following but this is very inefficient, is there any other way to insert and ignore duplicates?
Copy code
myCollection.bulkWrite(
    *customers.map {
        updateOne<Customer>(
            Customer::id eq it.id,
            KMongoUtil.toBsonModifier(it, UpdateConfiguration.updateOnlyNotNullProperties),
            upsert()
        )
    }.toTypedArray()
)
Im checking first if there are entries with same id in db and then adding the ones that aren’t in the db yet
8 Views