Skip to content
Advertisement

In the MongoDB java driver, will methods produce an error if the optional `ClientSession` is null?

I’ve been creating an abstraction of the MongoDB java driver. Given the following block of code…

MongoCollection<Document> col = db.getCollection("something");
col.insertOne(session, someDocument);

Where session can be either null or an actual instance of ClientSession. Will I run into issues with this paradigm? I have many methods like this, including col.replaceOne(), col.deleteOne, col.countDocuments(), etc.

Advertisement

Answer

According to the MongoDB Repository, passing in a null ClientSession will throw an IllegalArgumentException.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement