MongoDB entry and deletion change to build an index

Source: Internet
Author: User
Tags mongodb sort
Basic Operation command Show DBS//View all libraries using test//Use library without words automatically create show collections//view created table add Db.test_collection.insert (); Key value pair JSON data for (i=3;i<100;i++) Db.test_collection.insert ({_id:i,x:i})//Loop Add find Db.test_collection.find (); Find all fields Db.test_collection.find ({_id:1})//Condition Lookup Db.test_collection.find (). Count (); Statistics number Db.test_collection.find (). Skip (3). Limit (5). Sort ({_id:1}); Filter out the first three, limit 5, Sort by ID update db.test_collection.update ({x:45},{x:888}); Db.test_collection.update ({x:100},{$set: {y:888}},{z:100}); Specify field modification Db.test_collection.update ({y:100},{y:999},true)//If the data found does not exist then it will be written to multiple data modifications by default only the first bar is modified Db.test_ Collection.update ({c:1},{$set: {c:2}},false,true) prevents misoperation to delete db.test_collection.remove ({c:2}) only with Set update; Delete Table Db.test_collection.drop (); Add index Db.test_collection.ensureIndex ({x:1}); Single-key index view index db.test_collection.getIndexes (); Multi-key index Db.test_collection.insert ({x:[1,3,4,5]}) composite index db.test_collection. Ensureindex ({x:1,y:1}) expired index Db.test_ Collection. Ensureindex ({time:1},{expireafterseconds:10}), ExpireafterseConds: Full-text retrieval of seconds
Db.test.find ({$text: {$search: "CC"}}) Db.test.find ({$text: {$search: "AA bb cc"}}) by default is | | Db.test.find ({$text: {$search: "AA Bb-cc"}}) does not contain the CC string Db.test.find ({$text: {$search: "\" aa\ "\" bb\ "\" Cc\ "}}) default is & &
Full-Text Search similarity query Db.test.find ({$text: {$search: "cc SS"}},{score:{$meta: "Textscore"}}) split-rate, you can sort Db.test.find ({$text: {$ Search: "cc ss"}},{score:{$meta: "Textscore"}). Sort ({score:{$meta: "Textscore"}) see personal notes for details
Http://note.youdao.com/noteshare?id=c4c9cb4e6d708ce6e9784146098a1e7a&sub=5AF0A02626B0433B9AB7D9993D1602EA
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.