Created
October 14, 2022 06:01
-
-
Save AntonioDiaz/331939b6add3025a2126e8195842efbf to your computer and use it in GitHub Desktop.
Update Mongo DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testReplaceDocument() { | |
MongoCollection<Document> artists = testDb.getCollection("artists"); | |
Bson queryFilter = new Document("_id", band1Id); | |
Document myBand = artists.find(queryFilter).iterator().tryNext(); | |
Assert.assertEquals( | |
"Make sure that the band created in the database is" | |
+ " the same as the band retrieved from the database", | |
bandOne, | |
myBand); | |
Document replaceBand = new Document(); | |
replaceBand.append("title", "Gorillaz"); | |
artists.replaceOne(eq("_id", band1Id), replaceBand); | |
Document myNewBand = artists.find(queryFilter).iterator().tryNext(); | |
Assert.assertEquals(myNewBand.get("_id"), band1Id); | |
Assert.assertEquals(myNewBand.get("title"), "Gorillaz"); | |
Assert.assertNull(myNewBand.get("num_albums")); | |
Assert.assertNull(myNewBand.get("genre")); | |
Assert.assertNull(myNewBand.get("rating")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment