Skip to content

Commit 911b120

Browse files
committed
Add test case for matching an array subdocument with ObjectId #232
1 parent 2efad7f commit 911b120

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,25 @@ void testUpdateArrayMatch_updateMany() throws Exception {
34843484
);
34853485
}
34863486

3487+
// https://github.com/bwaldvogel/mongo-java-server/issues/232
3488+
@Test
3489+
void testUpdateArrayMatch_ObjectId() throws Exception {
3490+
collection.insertOne(json("_id: 1")
3491+
.append("myArray", List.of(new Document("_id", new ObjectId(123, 456)))));
3492+
3493+
collection.updateOne(
3494+
and(eq("_id", 1), eq("myArray._id", new ObjectId(123, 456))),
3495+
set("myArray.$.name", "new name")
3496+
);
3497+
3498+
assertThat(collection.find())
3499+
.containsExactly(json("_id: 1")
3500+
.append("myArray", List.of(
3501+
new Document("_id", new ObjectId(123, 456))
3502+
.append("name", "new name")
3503+
)));
3504+
}
3505+
34873506
// https://github.com/bwaldvogel/mongo-java-server/issues/32
34883507
@Test
34893508
void testUpdateWithNotAndSizeOperator() throws Exception {

0 commit comments

Comments
 (0)