What I am trying to do is very simple but I'm not sure why it's not working. What I'm trying to do is query the database on _id, if it matches, then update a specific record in the document it found.
BasicDBObject basic = new BasicDBObject();
basic.put("_id", id);
FindIterable<Document> cursor = collection.find(basic);
if(cursor == null){
Document tableEntry = new Document();
tableEntry.put("_id", id);
tableEntry.put("longitude", longitude);
tableEntry.put("latitude", latitude);
tableEntry.put("status", status);
collection.insertOne(tableEntry);
closeConnection();
}else{
for(Document doc : cursor){
doc.put("status", "full");
}
}
After running this and checking the database, it doesn't seem to update. I currently have 1 document in the database and it doesn't update that. I am using the mongo java 3.4.2 driver.