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)