@@ -1568,6 +1568,44 @@ public void Index_Example_2()
1568
1568
result . Should ( ) . Be ( "cuisine_1_name_1" ) ;
1569
1569
}
1570
1570
1571
+ [ Fact ]
1572
+ public void Exploiting_The_Power_Of_Arrays_Example ( )
1573
+ {
1574
+ RequireServer . Check ( ) . Supports ( Feature . ArrayFilters ) ;
1575
+
1576
+ var document = new BsonDocument
1577
+ {
1578
+ { "_id" , 1 } ,
1579
+ { "a" , new BsonArray { new BsonDocument ( "b" , 0 ) , new BsonDocument ( "b" , 1 ) } }
1580
+ } ;
1581
+
1582
+ var arrayUpdatesTestCollectionName = "arrayUpdatesTest" ;
1583
+ var testDatabase = client . GetDatabase ( "test" ) ;
1584
+ testDatabase . DropCollection ( arrayUpdatesTestCollectionName ) ;
1585
+ var arrayUpdatesTestCollection = testDatabase . GetCollection < BsonDocument > ( arrayUpdatesTestCollectionName ) ;
1586
+ arrayUpdatesTestCollection . InsertOne ( document ) ;
1587
+
1588
+ // Start Exploiting The Power Of Arrays Example
1589
+ var collection = client
1590
+ . GetDatabase ( "test" )
1591
+ . GetCollection < BsonDocument > ( "arrayUpdatesTest" ) ;
1592
+
1593
+ collection . UpdateOne (
1594
+ Builders < BsonDocument > . Filter . Eq ( "_id" , 1 ) ,
1595
+ Builders < BsonDocument > . Update . Set ( "a.$[i].b" , 2 ) ,
1596
+ new UpdateOptions ( )
1597
+ {
1598
+ ArrayFilters = new List < ArrayFilterDefinition < BsonValue > > ( )
1599
+ {
1600
+ "{ 'i.b' : 0 }"
1601
+ }
1602
+ } ) ;
1603
+ // End Exploiting The Power Of Arrays Example
1604
+
1605
+ var result = arrayUpdatesTestCollection . Find ( "{}" ) . FirstOrDefault ( ) ;
1606
+ result . Should ( ) . Be ( "{ \" _id\" : 1, \" a\" : [{ \" b\" : 2 }, { \" b\" : 1 }] }" ) ;
1607
+ }
1608
+
1571
1609
// private methods
1572
1610
private IEnumerable < BsonDocument > ParseMultiple ( params string [ ] documents )
1573
1611
{
0 commit comments