Installation of mongodb in Ubuntu and some simple operation notes

Time:2020-3-22

First install mongodb and input at the terminal:

Copy codeThe code is as follows:
sudo apt-get install mongodb 

Then start the mongodb database:

Copy codeThe code is as follows:
mongod 

This error may occur:

Copy codeThe code is as follows:
mongod –help for help and startup options 
mongod: symbol lookup error: mongod: undefined symbol: _ZN7pcrecpp2RE4InitEPKcPKNS_10RE_OptionsE 

Install mongodb-10gen to resolve this error:
Get the download 10 Gen public key:

Copy codeThe code is as follows:
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv 7F0CEB10 

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

Copy codeThe code is as follows:
echo ‘deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen’ | sudo tee /etc/apt/sources.list.d/10gen.list 

To install mongodb-10gen:

Copy codeThe code is as follows:
sudo apt-get update and then sudo apt-get install mongodb-10gen 

If there is a conflict between the prompt and remove mongodb clients, you can uninstall remove mongodb clients and install them again:

Copy codeThe code is as follows:
sudo apt-get remove mongodb-clients 
sudo apt-get install mongodb-10gen 

In this way, perform mongod to see the effect.
 
Some simple operations of mongodb:
Input at terminal(mongod must be started):

Copy codeThe code is as follows:
mongo 

Connect to test by default.
 
To view an existing database:

Copy codeThe code is as follows:
show dbs 

Delete database:

Copy codeThe code is as follows:
Use < – Database – >
db.dropDatabase()     

Create database:
 

Copy codeThe code is as follows:
Use < – Database – >

Stored data:
 

Copy codeThe code is as follows:
use test 
a = {“name”:”moneyinto”} 
b = {“age”:”23″} 
Db.test.insert (a) / / A, B store in different locations
db.age,insert(b) 

View data:

Copy codeThe code is as follows:
use test 
db.test.find() 
db.age.find() 

Delete age in database test:

Copy codeThe code is as follows:
DB. Age. Remove() / / delete
DB. Age. Find() / / check to see if it is deleted

Keep accumulating and updating!

Recommended Today

Python basics Chinese series tutorial · translation completed

Original: Python basics Python tutorial Protocol: CC by-nc-sa 4.0 Welcome anyone to participate and improve: a person can go very fast, but a group of people can go further. Online reading Apache CN learning resources catalog introduce Seven reasons to learn Python Why Python is great Learn Python introduction Executing Python scripts variable character string […]