What is the correct method to update a document while using Mongo Cursor?
问题 I am trying to update a document in Mongo DB using cursor. My Mongo DB Java driver version is 3.3.0. Following is my code snippet. MongoCollection<Document> collection = mongoDb.getCollection("customer"); MongoCursor<Document> cursor = collection.find().iterator(); try{ while(cursor.hasNext()){ Document oldDoc = cursor.next(); //created new Document newDoc collection.replaceOne(oldDoc, newDoc); } }catch(Exception e){ e.printStackTrace(); } Though this way, I can update the document, I think