I am creating a web application in Node.js with MongoDB because the back finish. Things I desired to know is, what's the generally recognized procedure, if any is available, for creating initial collections and inhabiting all of them with initial data like a whitened list for names or lists of predefined constants.
From what I've come across, MongoDB produces collections unconditionally whenever information is placed in to the database and also the collection being placed into does not already exist. Could it be standard to allow these implicit insertions take proper care of collection creation, or do people using MongoDB have scripts setup which build the primary structure and place any needed initial data? (For instance, when utilizing MySQL I'd possess a .sql script that we can go to dump and rebuild /repopulate the database on your own).
Appreciate any help.
There's is completely pointless to make use of setup scripts basically to create collections and databases appear. Both DB and collection creation is performed lazily.
Rember that MongoDB is really a completely schema free document store so there is no method to even setup a particular schema ahead of time.
You will find tools open to dump and restore database content provided with mongo.
Now, in case your application needs initial data (like configuration parameters or whitelists as if you suggest) it's often best practice to possess the application components set available online for own data when needed and provide data migration pathways too.
It is the character of Mongo to produce everything that doesn't exist. This enables a really flexible and agile development as you are not constrainted to types or need to see if
table x already is available before focusing on it. If you want to create collections dynamically, just have it in the database and arrange it if (whether it is available or otherwise).
If you're searching for a particular object, make sure to check it (not null or maybe a particular key is available) since it may affect your code if you use null objects.