0

Since in MongoDB , databases and collections are created dynamically or at runtime. What if I accidentally created the collection or database ,How can these situations be handeled?

for example : I need to insert the data in collection "employee" and i misspelled the collection name to "emplyee" , it leads to creation of new collection named "emplyee" . How can i make sure it doesnt create the collection called "emplyee"?

Sarthak Gupta
  • 824
  • 12
  • 23
  • 1
    Are you asking how to prevent a typo in a programmatic environment ???? – Eric Aug 08 '17 at 19:20
  • Depending on the API in use there generally are functions for this. For example if the collection is meant to be called "employee" and actually exists with that name, but somehow some code tried to access "emplyee" which **does not exist**, then you can specifically set to **not create the collection**. This is generally implemented as the `strict` option. For example with node.js `db.collection("emplyee",{ "strict": true },function(err,collection) {...` would throw an error if the collection did not actually exist. – Neil Lunn Aug 08 '17 at 22:07
  • Already answered here: [What is MongoDBs strict mode and is it a good idea to use?](https://stackoverflow.com/questions/21587344/what-is-mongodbs-strict-mode-and-is-it-a-good-idea-to-use) – Neil Lunn Aug 08 '17 at 22:08
  • @NeilLunn Thanks – Sarthak Gupta Aug 09 '17 at 02:59

0 Answers0