Installing MongoDB
sudo apt-get install MongoDB
... ...
Setting up client connections
Open File/etc/mongodb.conf Note permissions
Modify bind_ip=127.0.0.1 to bind_ip=0.0.0.0
Setting the connection user name and password and common commands
Enter MongoDB Interactive mode
>mongo
Create a connected user
>use Admin
>db.adduser (' username ', ' password ')
User authentication
>db.auth (' username ', ' password ')
View data sets
>db.collections
... ...
View the list of users
>db.system.users.find ()
View All Users
>show User
Delete User
>db.removeuser (' username ')
View all databases
>show DBS
View Data Set Status
>db.printcollectionstats ()
View Database Introduction
>show profile
Delete a data set
>db.demo_col.drop ()
Delete current Database
>db.dropdatabase ()
Service startup and shutdown
sudo service MongoDB start
sudo service MongoDB stop
Delete and change [ database name Demodb]
Add data
>db.demodb.save ({' name ': ' Bob ', ' email ': [' [email protected] ', ' [email protected] '], ' sex ': 1})
modifying data
Format: Db.collection.update (criteria, objnew, Upsert, Multi)
Criteria:update query conditions, similar to those in the SQL update query
Objnew:update objects and some updated operators (such as $, $inc ... ) can also be understood as the SQL update query within the set after the
Upsert: This parameter means that if there is no record of update, insert Objnew,true is inserted, default is False, not inserted.
Multi:mongodb default is False, only update the first record found, if this parameter is true, the condition is checked out all the records are updated.
>db.demodb.update ({' name ': ' Bob '},{' $set ': {' sex ': 0},upsert=true,multi=true})
Delete data
>db.demodb.remove ({' name ': ' Bob '})
Delete all records
>db.demodb.remove ()
Querying all data
>db.demodb.find ()
Query the topmost piece of data
>db.demodb.findone ()
Query the data for a specified number of bars based on criteria
>db.demodb.find ({' Sex ': 0}). Limit (2)
Skips a specified number of bars
>db.demodb.skip (10)
Sorting sort
>db.demodb.find ({' Sex ': 0}). Sort ({' name ':-1})
Count operations
>db.demodb.find ({' Sex ': 0}). Count ()
>db.demodb.count ()
Querying for specified columns, removing duplicates
>db.demodb.distinct (' sex ')
Sub-Object Lookup
>db.demodb.distinct ({' addr.province ': ' Beijing '})
Conditional operator Lookup
GT: Greater Than
LT: less than
GTE: greater than or equal to
LTE: Less than or equal to
NE: Not equal to
In:in contains $in: [1,2,3,4]
Type: numeric type [Double 1, String 2, Object 3,array 4, binary data 5,object ID 7, boolean 8,date 9,null 10,reg 11,js Code 13 , 32-bit integer, timestamp 17,64-bit integer 18,]
exist: Presence $exist: False/true
Where:js query $where: ' this.sex=0 '
>db.demodb.find ({' sex ': {$in: [0,1]}})
Fuzzy query--using regular expressions
>db.demodb.find ({name:/^b.*/i})
Ubuntu System Installation MongoDB