MongoDB Tutorial Lesson 17th mongodb Common Command Database command Collection Operations Command

Source: Internet
Author: User
Tags mongodb tutorial

(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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.