简体   繁体   中英

How to release Mongo DB in production environment?

I've been playing around with Mongo DB recently in my spare time (for work I normally use relational DBs, or more recently RDF triple stores) and I have a question that has been bothering me. When you have developed an application that uses Mongo DB and it now needs to be deployed in the production environment, what is the recommended process for releasing the database?

To be clear, I'm not talking about simply deploying an existing database on a server, I'm more interested in how to initially create a database in a state that is usable for the application.

So for example, with an SQL database you might have a set of scripts that create the database, create all the required tables, initialise the tables with any required data, set up access rights, views, etc.

What is bothering me is that with Mongo if the database, tables etc don't exist when you query them then they are created automatically. However I'm aware that it's possible to write Mongo scripts in JS to perform sequences of Mongo commands.

So in short, I guess the question is do you need to go to the trouble of writing these setup and initialisation scripts, or is it simply a case of installing Mongo and pointing your application to it?

You probably have to do much less to set up mongo for production than a SQL database. And in many instances there's nothing that needs to be done but to point your application at an empty mongo instance.

You will sometimes want to seed certain collections with data. There are numerous approaches for doing this. You can use mongodump and mongorestore (they can work on individual collections or an entire database). You can load json files through your mongo driver, or via a higher level wrapper like mongoose.

You may also want to create indexes on certain collections. Higher level wrappers like mongoose will do this automatically, but you may want to write a script that calls ensureIndex with the indexes you want on your collections that you run from the command line. It doesn't matter of you have no documents in the database.

There are two ways I'd recommend in how to deploy MangoDB. The best would be to copy the db data directory with a single tar command. Then take the .tar file and exact it on your production environment. Make sure DB Versions are compatible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM