Db.collection no longer supports strict mode, so how can I assure that my code isn't making a new collection?

The latest changes in node-mongodb-native include deprecation of the {strict:true} option of the Db.collection method. I’ve failed to find any guidance for how to write code that is assured to only work with existing collections without using {strict:true}. Can you point me at something that shows the proper way to do this in the future?

Hello @John_Bito, welcome to the MongoDB Community forum!

The latest MongoDB NodeJS Driver v3.6 does have the Db.collection method working fine with both the strict: true and false (the default) options. It is not deprecated.

Please tell what is the version of NodeJS, MongoDB server and the MongoDB NodeJS Driver you are working with? You can also include the code you had tried along with the actual error / warning message you are seeing.

I guess the deprecation may not be released, as it was merged about 4 weeks ago, after 3.6.9 was finished. The Jira ticket doesn’t provide any rationale for this change, though it’s linked to the removal of the strict option from Db.createCollection saying the strict option has no effect on that method’s behavior.

The strict option does change the behavior of Db.collection. Perhaps the rationale is that it appears to provide some advantage over calling Db.listCollections separately when there’s not an actual advantage.