@@ -27,33 +27,27 @@ public static void main(String[] args) {
27
27
MongoDatabase database = mongoClient .getDatabase ("sample_mflix" );
28
28
MongoCollection <Document > collection = database .getCollection ("movies" );
29
29
30
- try {
31
- // Runs a bulk write operation for the specified insert, update, delete, and replace operations
32
- BulkWriteResult result = collection .bulkWrite (
33
- Arrays .asList (
34
- new InsertOneModel <>(new Document ("name" , "A Sample Movie" )),
35
- new InsertOneModel <>(new Document ("name" , "Another Sample Movie" )),
36
- new InsertOneModel <>(new Document ("name" , "Yet Another Sample Movie" )),
37
-
38
- new UpdateOneModel <>(new Document ("name" , "A Sample Movie" ),
39
- new Document ("$set" , new Document ("name" , "An Old Sample Movie" )),
40
- new UpdateOptions ().upsert (true )),
41
-
42
- new DeleteOneModel <>(new Document ("name" , "Yet Another Sample Movie" )),
43
-
44
- new ReplaceOneModel <>(new Document ("name" , "Yet Another Sample Movie" ),
45
- new Document ("name" , "The Other Sample Movie" ).append ("runtime" , "42" ))
46
- ));
47
- // Prints the number of inserted, updated, and deleted documents
48
- System .out .println ("Result statistics:" +
49
- "\n inserted: " + result .getInsertedCount () +
50
- "\n updated: " + result .getModifiedCount () +
51
- "\n deleted: " + result .getDeletedCount ());
52
-
53
- // Prints a message if any exceptions occur during the operations
54
- } catch (MongoException me ) {
55
- System .err .println ("The bulk write operation failed due to an error: " + me );
56
- }
30
+ // Runs a bulk write operation for the specified insert, update, delete, and replace operations
31
+ BulkWriteResult result = collection .bulkWrite (
32
+ Arrays .asList (
33
+ new InsertOneModel <>(new Document ("name" , "A Sample Movie" )),
34
+ new InsertOneModel <>(new Document ("name" , "Another Sample Movie" )),
35
+ new InsertOneModel <>(new Document ("name" , "Yet Another Sample Movie" )),
36
+
37
+ new UpdateOneModel <>(new Document ("name" , "A Sample Movie" ),
38
+ new Document ("$set" , new Document ("name" , "An Old Sample Movie" )),
39
+ new UpdateOptions ().upsert (true )),
40
+
41
+ new DeleteOneModel <>(new Document ("name" , "Yet Another Sample Movie" )),
42
+
43
+ new ReplaceOneModel <>(new Document ("name" , "Yet Another Sample Movie" ),
44
+ new Document ("name" , "The Other Sample Movie" ).append ("runtime" , "42" ))
45
+ ));
46
+ // Prints the number of inserted, updated, and deleted documents
47
+ System .out .println ("Result statistics:" +
48
+ "\n inserted: " + result .getInsertedCount () +
49
+ "\n updated: " + result .getModifiedCount () +
50
+ "\n deleted: " + result .getDeletedCount ());
57
51
}
58
52
}
59
53
}
0 commit comments