Skip to content

Instantly share code, notes, and snippets.

@dalmat36
Created April 3, 2015 16:35
Show Gist options
  • Select an option

  • Save dalmat36/01e2ba0c702de5fef32d to your computer and use it in GitHub Desktop.

Select an option

Save dalmat36/01e2ba0c702de5fef32d to your computer and use it in GitHub Desktop.
This code snippet shows how to find an existing document in a the MongoDB "people" collection and replace it.
//Update a person document by Id
Document updatedPerson = new Document("First Name", "Marilyn")
.append("Last Name", "Monroe")
.append("Description", "Actor");
collection.findOneAndReplace(eq("First Name", "Marilyn"), updatedPerson);
System.out.println("Result After Update\n");
printAllPeople();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment