Skip to content

Commit

Permalink
Add test case for matching an array subdocument with ObjectId #232
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaldvogel committed Dec 29, 2024
1 parent 2efad7f commit 911b120
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3484,6 +3484,25 @@ void testUpdateArrayMatch_updateMany() throws Exception {
);
}

// https://github.com/bwaldvogel/mongo-java-server/issues/232
@Test
void testUpdateArrayMatch_ObjectId() throws Exception {
collection.insertOne(json("_id: 1")
.append("myArray", List.of(new Document("_id", new ObjectId(123, 456)))));

collection.updateOne(
and(eq("_id", 1), eq("myArray._id", new ObjectId(123, 456))),
set("myArray.$.name", "new name")
);

assertThat(collection.find())
.containsExactly(json("_id: 1")
.append("myArray", List.of(
new Document("_id", new ObjectId(123, 456))
.append("name", "new name")
)));
}

// https://github.com/bwaldvogel/mongo-java-server/issues/32
@Test
void testUpdateWithNotAndSizeOperator() throws Exception {
Expand Down

0 comments on commit 911b120

Please sign in to comment.