(1) Database commands
A) Add user db.adduser (' name ', ' pwd ')
b) Delete user db.removeuser (' name ')
c) User authentication Db.auth (' name ', ' pwd ')
d) Copy database, copy db.copydatabase from Test library (' Test ', ' mydb ')
e) Delete Database Db.dropdatabase ()
f) Get all the collections under the Database Db.getcollectionnames ()
g) Stop MONGO Service Db.shutdownserver ()
h) using a database use dbname
i) View all collections under the database Show collections
j) View all DB show DBS
k) View current database status Db.stats ()
L) View User show Users
m) View Help Db.help ()
(2) Set operation
A) adding data, adding the first data to the collection creates the collection, assuming that the Char collection is created Db.char.save ({' name ': ' Weixiaobao ', ' age ': 23})
b) Storage Array object Db.char.save ({' name ': ' name123 ', ' addr ': [' Beijing ', ' Nanjing ']})
c) query all, query a db.char.find () Db.char.findOne ()
d) Conditional query (query the record named ' Weixiaobao ') db.char.find ({' name ': ' Weixiaobao '})
e) Limit the number of query bars (starting from the second bar to 10) db.char.find ({' name ': ' Weixiaobao '}). Skip (2). Limit (10)
f) The query returns the number of bars Db.char.find ({' name ': ' Weixiaobao '}). Count ()
g) sort (by name ascending, age descending) Db.char.find (). Sort ({' name ': 1, ' age ':-1})
h) Query the specified column to db.char.distinct (' name ')
i) Remove the set Db.char.drop ()
j) Create index Db.char.ensureIndex ({' Name ': 1, ' Age ': 1},{unique:true})
k) View index db.char.getIndexes ()
L) Delete index Db.char.dropIndex (' IndexName ')
m) Delete data db.char.remove ({' name ': ' Weixiaobao '})
N) Update data db.char.update ({' name ': ' Weixiaobao '},{' $set ': {' age ': 40}})
O) Condition query Db.char.find ({' age ': {$gt: 20}})
MongoDB Tutorial Lesson 17th mongodb Common Command Database command Collection Operations Command