UpdateOptions options = new UpdateOptions().upsert(true);
Bson filters = Filters.eq("id", 123456);
List<Bson> bsonArrayList = new ArrayList<>();
bsonArrayList.add(Updates.set("income", "$300k"));
UpdateResult updateResult = mongoExe.updateOne(filters, bsonArrayList, options);
The field name is income
, value is $200k
. It can’t update until I delete the $
bsonArrayList.add(Updates.set("income", "300k"));
how can I do to make it ?
why java mongodb driver update a value can’t start with $
?
2
Answers
The $ is a special character in MongoDB, see here for a description.
You can fix it by escaping the character, see here for how.
You can use literal:
or
eq
is just a container (or shorthand forDocument
) in this case.