требуется, чтобы оператор обновления выполнял две вещи:
(1) добавить в документ список оценок и что я мог бы сделать
(2) добавить номер 5 к индексу № 2 если _id документа равен 1
добавление номера 5 к индексу № 3, если _id документа не равен 1
Я мог бы сделать это, используя:
Код: Выделить всё
if (found.get("_id").equals("1")){
update = new Document("$set", new Document("Score.2" , 5.0));
}
else {
update = new Document("$set", new Document("Score.3" , 6.0));
}
Код: Выделить всё
update = new Document("$set",
new Document("$cond",
new Document("if", new Document("$eq", found.get("_id" , 1)))
.append("Score.2", 5.0)
)
);
new Document("$cond",
new Document("if", new Document("$ne", found.get("$_id" , 1))
.append("Score.3", 6.0)
)
);
Подробнее здесь: https://stackoverflow.com/questions/792 ... -statement