Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can mongo shell warn about operations on non-existing collections?

It happened several times that I made a typo in a collection name or forgot to switch database to that one which includes the desired collection. Mongo shell accepted silently all those commands. Is it possible that mongo shell will warn me if I try to execute a query on non-existing collection?

like image 509
Lukasz Wiktor Avatar asked Nov 10 '22 11:11

Lukasz Wiktor


1 Answers

From the MongoDB console, there is no direct way to prevent the scenarios you mention.

You could add authentication/authorization to certain databases to help prevent some types of unintentional actions.

The intentional design of MongoDb is that it delay creates collections.

Unless you've scripted the console start, you'll end up in a test database.

If you're using the console, it is presumed that you have administrator control, and understand the risks of direct manipulation. A collection that doesn't exist is perfectly normal in many workflows.

I'd suggest you consider evaluating one of the many GUI applications for managing Mongo databases.

Many drivers have support to confirm that a collection exists before use, and can throw an error if the specified collection does not.

If the feature was added, it would need to be opt-in.

like image 62
WiredPrairie Avatar answered Nov 15 '22 13:11

WiredPrairie