Hi,
I'm new to Mongo. I need to iterate documents in a query result, update a single field and save the document.
My understanding is that I need to iterate the query result with a cursor, get the record's _id, and then use that in the search query that is passed in the call to update();
The code below runs but the values never make it back to the database. I would be extremely grateful for any assistance. Thanks in advance.
I'm running a default out-of-the-box Mongo instance.
Here is the chunk of code that isn't working:
byte[] outputFile = new byte[10];
outputFile[0] = 40;
BasicDBObject newDocument = new BasicDBObject();
newDocument.append("$set", new BasicDBObject().append("SomeField", outputFile));
String id = cursor.curr().get("_id").toString();
BasicDBObject searchQuery = new BasicDBObject().append("_id", id);
fileCollection.update(searchQuery, newDocument, true, false);