MongoDB Learning Notes (iii)

Source: Internet
Author: User

Common directives

1. Go to the heavy

Db.runcommand ({distinct: ' person ', key: ' Home '});

  

2. Grouping

Db.runcommand ({group:{ns: Collection name, key: Grouped key, initial: initialization, $reduce: decomposition, Condition: condition, Finalize: Processor at completion)});d B.runcommand ( {group:{ns: ' person ', key: ' Email ', initial:{age:0}, $reduce: function (DOC,ACC) {if (doc.age>acc.age) {acc.age = Doc.age;acc.email = doc.email;}},condition:{age:{$gt: 10}},finalize:function (ACC) {print (acc.age);}});


3. Deleting a Collection

Db.runcommand ({drop: ' person '})

  

4. View database Information

Db.runcommand ({buildinfo:1})

  

Fixed collection

When setting up a collection, specify the size and number of documents, and if full, discard the last element and add the new element
Characteristics
No index
Very fast insertion and query
Suitable for writing logs
Create a Collection

Db.createcollection (' lessons ', {size:50,max:5,capped:true})

  

When inserting the sixth data, it overwrites the first data, which is a kind of structure of the queue.
Modify collection Information

Db.runcommand ({converttocapped: ' Courses ', size:6});

  

To turn a non-stationary set into a fixed set

Gridfs

is a MongoDB-brought file system that uses binary storage files. You can save a binary object in Bson format.
However, the volume of the Bson object cannot exceed 4M. So MongoDB offers Gridfs. Can make large files transparent
Split into small files (256K)
Uploading files
mongofiles-d files-l "E:\test.txt" put "test.txt"
See how many files Gridfs has
mongofiles-d Files List
deleting files
mongofiles-d files Delete "Test.txt"

Server-side scripting eval

Db.eval ("+");d B.system.js.insert ({_id: ' x ', Value: ' 234 '});d B.eval (' Return x '); 234

MongoDB Learning Note (c)

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.