ubuntu install mongodb to create account and library and add coordinate index analysis


Abstract: As a development, we use nosql more and more, the representative is mongodb, fast performance is good, but also the perfect creation of 2-dimensional index. Install mongodb on ubuntu to create account and library and add coordinate index

1 installation

1.1 installation php - mongodb

sudo apt-get install php-mongodb

1.2 installation mongodb - org

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

If it is ubuntu14

echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

If ubuntu16 or 18

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

The following

sudo apt-get update

sudo apt-get install -y mongodb-org

sudo service mongod start #  Start the

2 common start and other commands

sudo service mongod start #  Start the
sudo service mongod stop #  Shut down
ps aux | grep mongod  #  Check the process

Create tables, roles and permissions

3.1 Administrator Account

mongo --host 127.0.0.1

use admin

db.createUser(
... {
... user: "test",
... pwd: "test@1111",
... roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
... }
... )

db.getUser('test')

exit

3.2 Account and permissions of the object library administrator

mongo --host 127.0.0.1 -u 'test' --authenticationDatabase 'admin' -p 'test@1111'

use admin

db.auth('test','test@1111')

use lbs

db.createUser(
... {
... user: "testlbs",
... pwd: "testlbs1111",
... roles: [ { role: "readWrite", db: "lbs" },
... { role: "read", db: "lbs" } ]
... }
... )

exit

3.3 Object library index

mongo --host 127.0.0.1 -u 'testlbs' --authenticationDatabase 'lbs' -p 'testlbs1111'

db

use lbs

db

db.createCollection('lbs',{capped:false})

db.lbs.createIndex({'location':'2dsphere'})

db.lbs.createIndex({'uniqid':1},{unique:true})

4 uninstall

4.1 Close the daemon mongod

sudo service mongod stop

4.2 Uninstall the installed software package

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

0

4.3 Remove database and log files (the path of database and log files depends on the configuration in /etc/ mongod.conf file)

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

1

conclusion