-
Type:
Task
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.2.0
-
Component/s: API
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
The first way to perform an update to a document would be (from my point of view) something like this
Document tempDoc = new Document(); tempDoc.put("value", "new value"); collection.updateOne(Filters.eq("_id", 1), tempDoc);
but this leads to
Exception in thread "main" java.lang.IllegalArgumentException: Invalid BSON field name value
I have to wrap my update in another document
Document tempDoc = new Document(); tempDoc.put("value", "new value"); Document tempUpdateOp = new Document("$set", tempDoc); collection.updateOne(Filters.eq("_id", 1), tempUpdateOp);
This is strange because there is no need to wrap it. For the purpose of replacing a document there is another method replaceOne. Why do I have to wrap my update into another document for the updateOne call?