我正面临着一个问题。我正在尝试更新如果已经存在,否则插入如果不存在。我使用的是spring-mongo驱动程序的批量API。
DBCollection dbCollection = mongoTemplate.getCollection("supcInfo");
BulkWriteOperation bulkWriteOperation = dbCollection.initializeUnorderedBulkOperation();
BulkUpdateRequestBuilder builder = bulkWriteOperation.find(new BasicDBObject("_id", supcInfo.getSupc())).upsert();
BasicDBObject dbObject = new BasicDBObject("$set",new BasicDBObject("_id", supcInfo.getSupc()));
dbObject = dbObject.append("$set",new BasicDBObject("pogId", supcInfo.getPogId()));
dbObject = dbObject.append("$set",new BasicDBObject("mrp", supcInfo.getMrp()));
dbObject = dbObject.append("$set",new BasicDBObject("price", supcInfo.getPrice()));
dbObject = dbObject.append("$set",new BasicDBObject("primarySellerCode", supcInfo.getPrimarySellerCode()));
dbObject = dbObject.append("$set",new BasicDBObject("camsEnabled", supcInfo.isCamsEnabled()));
dbObject = dbObject.append("$set",new BasicDBObject("availability", supcInfo.getAvailability()));
dbObject = dbObject.append("$set",new BasicDBObject("updateTs", supcInfo.getUpdateTs()));
builder.updateOne(dbObject);
bulkWriteOperation.execute();但并不是所有字段都在更新。谁能告诉我原因和replaceOne工作很好,但它将重新创建索引,如果有任何。
https://stackoverflow.com/questions/41323737
复制相似问题