You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bulk upsert would be wonderful, as insertAll fails with a DuplicateKeyException if even one record is duplicated, and this exception cannot seem to be caught and ignored, such as in the following code:
privatefun <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()
}
@almogtavor Instead of upsert how can I update like this way
var bulkOps = mongoTemplate.bulkOps()
for(dto : List DTOs) {
Query query = new Query();
query.addCriteria(Criteria.where(ID).is(dto.getId()));
Update update = new Update()
.set(STATUS, dto.getStatus())
bulkOps.updateOne(query, update)
}
bulkOps.execute();
Mark Paluch opened DATAMONGO-1922 and commented
1 votes, 2 watchers
The text was updated successfully, but these errors were encountered: