Some operations commands for "MongoDB" MongoDB

Source: Internet
Author: User
Tags dname

We should first know the data structure of MongoDB: MongoDB: Library----Collection-->json Object

View

Show DBS//See which libraries are available
Show collections//See which collections are in the library

Library operations

Use library name//using a library, entering a library, creating a library
Library name. Dropdatabase ()//delete

Collection operations

The collection is added to the difference operation.

Db. Collection name. Insert (XX)//create collection Insert record
Db. Collection name. Drop ()//delete collection
Db. Collection name. Find ()//query
Db. Collection name. Update ()//Updates
Db. Collection name. Remove ()//delete

Add action

Insert a single record
Db.dept.insert ({"Deptno": Ten, "Dname": "Java"})
Inserting multiple records
Db.dept.insert ([{"Deptno": Ten, "Dname": "java"},{"Deptno": "Dname": "Java EE"}])


Query operations

Querying All records
Db.dept.find ()
Querying the records of deptno=10
Db.dept.find ({"Deptno": 10})
Query deptno>20 Records (other $gte, $lt, $lte, $ne)
Db.dept.find ({"Deptno": {$gt: 20}})
Query Dname records starting with the J letter
Db.dept.find ({"Dname":/^j/})
Query for records with a in dname
Db.dept.find ({"Dname":/a/})


Delete operation

Delete a deptno=10 record
Db.dept.remove ({"Deptno": 10})
Delete all records
Db.dept.remove ({})

Update action

Update all, the entire JSON object will be covered out
Db.dept.update ({"Deptno": 30},{"Phone": "1354444444"})
Partial update, modifying a property value
Db.dept.update ({"Deptno": 30},{$set: {"Phone": "1354444444"}})

Statistical operations

Total number of statistics records
Db.dept.count ()
Count the number of records that match the criteria
Db.dept.count ({"Dname": "Java"})

Paging operations

means skip the top 5, take the last 5

Db.user.find (). Skip (5). Limit (5)

Some operations commands for "MongoDB" MongoDB

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.