問題が発生しました。私はすでに存在していれば更新しようとしています。存在しなければ挿入します。私はspring-mongoドライバのBulk APIを使用しています。upsertでupdateoneを使用してmongoを一括更新できません
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を教えてもらえますか?正常に動作しますが、インデックスがあればそれを再作成します。
効果がない場合の例を追加できますか? 'convertToDBObjectToUpdate(supcInfo)'が何をしているのか不明です。あなただけが更新しようとしているときに一括書き込み操作が必要なのでしょうか? – Veeram
すみません。これはdbObjectです。私は5〜7個のフィールドを含むsupcinfoを更新しようとしていますが、最初と最後のものを更新するのは_idとupdateTsだけです。 { \t \t "supc": "supc15"、 \t \t "pogId":1354619、 \t \t "MRP":3322323、 \t \t "価格":99232323、 \t \t "primarySellerCode": "" 、 \t \t "camsEnabled":真、 \t \t "可用性": "入荷" \t} – cody123