@@ -14,32 +14,38 @@ public class InsertMany
1414
1515 public static void Main ( string [ ] args )
1616 {
17- Setup ( ) ;
17+ try {
18+ Setup ( ) ;
1819
19- // Creates a filter for all documents that have a "name" value of "Mongo's Pizza"
20- var filter = Builders < Restaurant > . Filter
21- . Eq ( r => r . Name , "Mongo's Pizza" ) ;
20+ // Creates a filter for all documents that have a "name" value of "Mongo's Pizza"
21+ var filter = Builders < Restaurant > . Filter
22+ . Eq ( r => r . Name , "Mongo's Pizza" ) ;
2223
23- // Finds all documents that match the filter
24- var foundRestaurants = _restaurantsCollection . Find ( filter ) . ToList ( ) ;
24+ // Finds all documents that match the filter
25+ var foundRestaurants = _restaurantsCollection . Find ( filter ) . ToList ( ) ;
2526
26- Console . WriteLine ( $ "Number of restaurants found before insert: { foundRestaurants . Count } ") ;
27+ Console . WriteLine ( $ "Number of restaurants found before insert: { foundRestaurants . Count } ") ;
2728
28- // Prints extra space for console readability
29- Console . WriteLine ( ) ;
29+ // Prints extra space for console readability
30+ Console . WriteLine ( ) ;
3031
31- Console . WriteLine ( "Inserting documents..." ) ;
32+ Console . WriteLine ( "Inserting documents..." ) ;
3233
33- // Inserts the documents by using a helper method
34- InsertManyRestaurants ( ) ;
34+ // Inserts the documents by using a helper method
35+ InsertManyRestaurants ( ) ;
3536
36- // Finds all documents that match the filter after the insert
37- foundRestaurants = _restaurantsCollection . Find ( filter ) . ToList ( ) ;
37+ // Finds all documents that match the filter after the insert
38+ foundRestaurants = _restaurantsCollection . Find ( filter ) . ToList ( ) ;
3839
39- // Prints the number of documents found
40- Console . WriteLine ( $ "Number of restaurants inserted: { foundRestaurants . Count } ") ;
40+ // Prints the number of documents found
41+ Console . WriteLine ( $ "Number of restaurants inserted: { foundRestaurants . Count } ") ;
4142
42- Cleanup ( ) ;
43+ Cleanup ( ) ;
44+
45+ // Prints a message if any exceptions occur during the operation
46+ } catch ( MongoException me ) {
47+ Console . WriteLine ( "Unable to insert due to an error: " + me ) ;
48+ }
4349 }
4450
4551 private static void InsertManyRestaurants ( )
0 commit comments