I am using MongoDB Java Driver 3.4 and want to update a document (with id "12") in a Mongo-DB collection. Currently, the document looks as follows:
{"id" : "12", "Data" : [{"Author" : "J.K. Rowling",
"Books" : {"Harry Potter 1" : "$15.99", "Harry Potter 2" : "$16.49", "Harry Potter 3" : "$19.49"}},
{"Author" : "Philip Roth",
"Books" : {"American Pastoral" : "$12.99", "The Human Stain" : "$39.49", "Indignation" : "$29.49"}}
]}
I want to update this document by adding the following object to array "Data":
{"Author" : "Stephen King", "Books" : {"Rose Red" : "$12.69", "Faithful" : "$9.49", "Throttle" : "$8.49"}}
To this end I wrote the following java code:
Document doc = new Document().append("Author", "Stephen King")
.append("Data", new Document("Rose Red", "$12.69")
.append("Faithful" : "$9.49")
.append("Throttle" : "$8.49"));
collection.update({"id", "12"}, {$push: {"Data" : doc.toJson()}});
The IDE indicates there is something wrong with the last statement (collection.update...) by showing me this:
I don't know what this error message is supposed to tell me. There is a semicolon at the end of the statement. Does anybody know what's wrong with the java code?
P.S.: This is not a duplicate to (MongoDB Java) $push into array My question relates to Java Driver 3.4. The other question relates to an earlier version with totally different classes.