Most of the time, we need to initialize database settings, such as creating indexes, especially when configuring multiple MongoDB servers, or when initializing and archiving.
Most of the time, we need to initialize database settings, such as creating indexes, especially when configuring multiple MongoDB servers, or when initializing and archiving.
Most of the time, we need to initialize database settings, such as creating indexes, especially when configuring multiple MongoDB servers, or when initializing and archiving.
Run the following command to execute a js file:
./Mongo IP/DBName init. js
The content of the init. js file can be written as follows:
Db. dropDatabase (); // Delete the database to clear data
Db. message. ensureIndex ({display_id: 1}); // create an index on the display_id field of the message set in the current database
It is strange that an index can be created even if the database is deleted, but this can be used.
When the program is connected to the database in the future, if there is no MongoDB, the database will be created. The same applies to collections.
MongoDB details: click here
MongoDB: click here
Related reading:
MongoDB backup and recovery
CentOS compilation and installation of MongoDB
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
How to create a new database and set in MongoDB
MongoDB beginners must read (both concepts and practices)
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]