Installation and Usage |
MongoDB service can be run on Linux, Windows or Mac OS X platform, supporting 32 bit and 64 bit system. Default port is 27017. MongoDB store data to file (Linux default path is /data/db, Windows default path is C:\data\db). To improve efficiency, use memory mapping file to manage.
MongoDB requires versions 2.6/3.x/4.x (up to 4.2.x), of which only version 4.2.x supports Mongo replication set deployment.
MongoDB is a simple, easy-to-use product that can be unzipped and used. The MongoDB data storage location defaults to C:\data\db. If you do not use the default location, you must create the data storage location before you start service, such as creating a D:\mongodb\data\db is storage location.
Execute the mongod command start service in the bin folder of the MongoDB installation directory:
mongod.exe --dbpath D:\mongodb\data\db --port 27010
Where "--dbpath" and "–-port" are optional parameters that specify the storage path and port number, respectively. If not specified, the default storage location is C:\data\db, default port number 27017.
If the prompt message is waiting for connections, it indicates that the service is started successfully.
net stop MongoDB
mongod.exe --dbpath D:\mongodb\data\db --install -logpath D:\mongodb\log --serviceName MongoDB
Where, "--logpath" is used to specify the storage path of logs, and "--serviceName" is used to set the registered service name.
net start MongoDB
net stop MongoDB
mongod.exe --dbpath "D:\mongodb\data\db" --remove --serviceName "MongoDB"
On the Linux system, MongoDB can also be used by the start service after decompression.
tar -zxf mongodb-xxxxxxx.tgz
mkdir /data
mkdir /data/db
Please start the MongoDB service as the root user. For example, you can execute the following command according to the default storage location and port number:
./mongodb-xxxxxxx/bin/mongod
If the prompt message is waiting for connections, it indicates that the service is started successfully.
There are three ways to stop the MongoDB service:
mongod --shutdown --dbpath /database/mongodb/data/
ps -ef | grep mongo
kill -2 {PID}
After start service, the prompt in the command prompt window is waiting for connections.
You can connect to the service through the MongoDB client to verify its availability. Open cmd.exe and execute the following command:
mongo.exe --host localhost --port 27010
Where "--host" specifies an existing MongoDB service address and "--port" specifies a started port.
You can create a database specifically to store the map tiles:
use sampledb
At this point, a database named sampledb is created. But it still doesn't exist in the database list, you need to insert at least one collection into it:
db.tile.insert({"name":"map"})
When finished, you can view the database in MongoDB with the following command:
show dbs
To view the database currently in use:
db
You can also view all collections in a database:
show collections
If you do not specify a database when you add a slice library in the distributed slicing service, iServer creates a database name called smtiles and stores the tiles by default.
In order to ensure the security of the database you use, you need to set the user name and password for the database, which can be accessed only after authentication. The following provides a detailed introduction to the steps for enabling security controls in MongoDB 2.x and MongoDB 3.x.
Take the sampledb database as an example:
use sampledb
Create a user and set the username and password, for example:
db.addUser({user:"user1",pwd:"password",roles:["readWrite","dbAdmin"]})
Then restart MongoDB in secure mode to enable permission control, adding -- auth as follows:
mongod.exe --dbpath D:\mongodb\data\db --auth --port 27010
After executing the above command, security control will be enabled for all databases in D:\mongodb\data\db. When accessing and using databases in this directory, you need to enter the set username and password to connect successfully.
Note: If you do not enable security control, the user account is not enabled and the database is still in an anonymous access state.
First, create an administrator user and database. The role must be the built-in administrator role userAdminAnyDatabase in MongoDB:
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
Stop the MongoDB service and restart it in safe mode MongoDB, adding --auth:
mongod.exe --dbpath D:\mongodb\data\db --auth --port 27010
To connect to the service through the MongoDB client, creating users, databases, etc. In MongoDB 3.x series versions requires authentication of the administrator user and database. Returning '1' indicates successful authentication.
mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
After successful authentication, create ordinary users and databases, for example:
use test
db.createUser(
{
user: "myTester",
pwd: "xyz123",
roles: [ { role: "readWrite", db: "test" },
{ role: "read", db: "reporting" } ]
}
)
Once created, you can connect to MongoDB in iServer. When connecting to MongoDB in iServer, it is necessary to connect to the regular user myTester and databases with read and write permissions, and cannot connect to administrator users and databases.