Some simple MongoDB common command collection

Source: Internet
Author: User
Tags mongodb
1. $all means to match an array with multiple elements
2. $slice specify the offset value and the number of elements you want to return
Db.user.find (aa,{"common": {"$slice": 10}})


3. Db.user.ensureIndex ({"Name": 1})
Add index
4. Db.user.drop () Delete collection
5. Db.user.remove () Remove the data in the collection, you need to add query


6. Use Db.user.find (). Hint ({"username": 1}) to force an index to query using hint
7. Db.user.ensureIndex ({"username": 1},{"unique": true}) Create a unique index
8. Db.user.getIndexes () View index information in a given collection


9. Db.user.aggregate ({$group: {"_id": {"date": "$date", "NUMA": "$numa"}});
Db.getcollectionnames (); Query all collection names under the library table


One. Show collections; View database under Collection commands
Show DBS; View Database Commands
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.