Я пытаюсь обновить сразу несколько полей в одном документе MongoDB, но обновляется только одно поле. У меня есть коллекция пользователь, в которой пользователи уникально определены customer_user_id. Я хочу обновить определенные поля birth_year и страны.
Это то, что я делаю:
// Define the search query:
DBCollection col = md.getDb().getCollection("user");
BasicDBObject searchQuery = new BasicDBObject("customer_user_id", customer_user_id);
// Define the update query:
BasicDBObject updateQuery = new BasicDBObject();
updateQuery.append("$set", new BasicDBObject().append("birth_year", birth_year);
updateQuery.append("$set", new BasicDBObject().append("country", country);
log.info("Update query: " + updateQuery);
col.update(searchQuery, updateQuery);
К сожалению, обновляется только поле страна, а зарегистрированное updateQuery выглядит следующим образом:
Обновить запрос: { "$ set": { "страна": "Австрия" }}