-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for reactive bulk operations [DATAMONGO-1922] #2821
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
Comments
Bulk upsert would be wonderful, as private fun <T: DataModel> insertAllValid(uri: String, transformer: (JSONObject) -> InputModel<T>) {
getJSON(uri).map(transformer)
.map(InputModel<T>::toDataModelIfValid)
.mapNotNull { it!! }
.collectList()
// Would be nice to have `::upsertAll` that bulk inserts new + updates existing records
.flatMapMany(mongoTemplate::insertAll)
.onErrorResume(DuplicateKeyException::class.java) { e ->
println(e)
Flux.empty()
}
.doOnNext { logger.debug(it.toString()) }
.doOnError { logger.error(it.toString()) }
.subscribe()
} |
@tgrushka A nice workaround: reactiveMongoTemplate.getCollection(config.getCollection()).flatMap(mongoCollection -> {
var operations = entities.stream().map(entity -> {
Document doc = new Document();
reactiveMongoTemplate.getConverter().write(entity, doc);
var filter = new Document("externalId", entity.getExternalId());
return new UpdateOneModel<Document>(filter, new Document("$set", doc), new UpdateOptions().upsert(true));
}).toList();
return Mono.from(mongoCollection.bulkWrite(operations));
}) |
@almogtavor Instead of upsert how can I update like this way |
Mark Paluch opened DATAMONGO-1922 and commented
1 votes, 2 watchers
The text was updated successfully, but these errors were encountered: