Install MongoDB in Ubuntu and perform some simple notes

  • 2020-05-14 05:19:56
  • OfStack

First install MongoDB and enter at the terminal:


sudo apt-get install mongodb 

Then start the database MongoDB:

mongod 

Errors like this may occur:

mongod --help for help and startup options 
mongod: symbol lookup error: mongod: undefined symbol: _ZN7pcrecpp2RE4InitEPKcPKNS_10RE_OptionsE 

Now install mongodb-10gen to fix this error:
Get download 10-gen public key:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 

Create a/etc apt/sources list. d / 10 gen:

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list 

Install mongodb - 10 gen:

sudo apt-get update and then sudo apt-get install mongodb-10gen 

If there is a conflict with remove mongodb-clients, you can uninstall remove mongodb-clients and install:

sudo apt-get remove mongodb-clients 
sudo apt-get install mongodb-10gen 

So I'm going to do mongod 1 and I'm going to see 1.

Some simple things to do about MongoDB:
Input at the terminal (mongod must have been started) :

mongo 

Connect to test by default.

View the existing database:

show dbs 

Delete database:

use <-database->   //<-database-> Is the name of the database to delete  
db.dropDatabase()     

Create a database:

use <-database->   //<-database-> For the name of the database to be created, it automatically creates the database and connects to it  

Stored data:

use test 
a = {"name":"moneyinto"} 
b = {"age":"23"} 
db.test.insert(a)   //a,b The storage location is different  
db.age,insert(b) 

View data:

use test 
db.test.find() 
db.age.find() 

Delete age in database test:

db.age.remove()      // delete  
db.age.find()      // To view 1 Let's see if I deleted it  

Continue to accumulate, continue to update!


Related articles: