Fixed set of MongoDB (optimized efficiency)

Source: Internet
Author: User
Tags mongodb collection

The MongoDB fixed collections (Capped Collection) and large file management (GRIDFS) Capped Collection fixed collections (Capped Collection) are well-performing with fixed-size collections to LRU (Least Recently used the least recently used) rule and insert order for age-out (aging out) processing, automatically maintaining the insertion order of objects in the collection, pre-sizing when created, and if the space is exhausted, the newly added object will replace the oldest object in the collection and always keep up-to-date data.
View the collection's status information Db.cot1.stats (); View the state information of the collection COT1 delete the specified set Db.collection1.drop (); Delete Collection1 collection in MongoDB collection creation is implicitly created by default and can be created using createcollection display db.createcollection ("collect"); Delete the specified database Db.dropdatabase (); Delete current database query All databases show DBS//query all databases Show all collections in current library show tables; or show collections; The functional characteristics of a fixed collection can be inserted and updated, but the update cannot exceed the size of the collection, otherwise the update fails and no deletion is allowed, but the drop () can be called to delete all rows in the collection, but the collection needs to be explicitly rebuilt after the drop. On a 32-bit machine on a cappped The maximum value of collection is only limited by the system file size on the 482.5m,64 bit.
Fixed set properties and Usage:  Property 1: Inserting a fixed set is extremely fast   Property 2: Query output in the order of insertion is extremely fast   attribute 3: Ability to retire the oldest data when inserting the latest data   Usage 1: Store log information   Usage 2: Cache Some small amount of documents   create fixed collections   Unlike normal collections, fixed collections need to be displayed created using the CreateCollection command  eg. Db.createcollection ("collect", {capped:true, size:10000});  creates a fixed collection of collect, size 10000 bytes, and can specify the number of documents, plus Max : 100 Properties .  Note: Specify the upper limit of the document, you must specify the size, the document limit is eliminated when the capacity is not full, if full, according to the capacity limit to retire .  can be re-created capped collection specifies the maximum number of documents that can be stored in collection, but this is to specify size, because the size is always checked before Maxrownumber is checked. You can use Validate () See how much space a collection has used, and decide how large the size is to . > db.createcollection ("Mycappedcoll", {Capped:true,size:10000,max :  {"OK": 1} > db.mycappedcoll.validate ();  When creating collection there is also a parameter "Autoindexid", the value can be "true" and " False "to determine if you need to create an index on" _id ", such as  > db.createcollection (" Mycappedcoll ", {capped:true,size:10000,max:100, Autoindexid:false})   The generic collection is created by default, but is not created for capped collection. Capped collection cannot be Shard, which makes sense, A table that is often refreshed and fixed in size does not make much sense to do sharding (sharding) .  www.2cto.com   Conversion collection   Converting a normal collection to a fixed set requires the use of ConvertToCapped command  db.runcommand ({converttocapped: "Test", size:10000}); Convert test universal set to fixed set, size 10000 bytes .  Natural sort   Fixed collection documents are stored in the order in which they are inserted, by default the query is returned in the order of insertion, or you can use $natural to adjust the return order.  db.mycappedcolt.find (). Sort ({"$natural": 1}); The parameter 1 indicates the default order, and 1 is the opposite .  determines whether the collection is a fixed set  db.colt.iscapped ();   View the collection state information  db.colt.stats ();   gridfs gridfs is a mechanism for storing binary files in MongoDB, using Gridfs for several:  to store huge files, such as videos, high-definition images, and so on. Using Gridfs can simplify the need .  Gridfs will directly take advantage of the replication or fragmentation mechanisms that have been established, and it is easy to recover and extend them.  gridfs can avoid problems with the file system where users upload content.  GRIDFS does not produce disk fragmentation   www.2cto.com  gridfs stores data  grdifs uses two tables to store data:  files contains metadata objects  chunks binary blocks containing some other pertinent information .  In order for multiple Gridfs to be named a single database, both the file and the block have a prefix, by default, the prefix is FS, so any default Gridfs storage will include the namespace Fs.files and Fs.chunks.   Various third-party languages can change their prefixes   use Gridfs mongofiles mongofiles is a tool to manipulate Gridfs from the command line   four commands: put (store), get (Get/download), List, delete (delete)   eg. ./mongofiles put testfile.zip ./mongofiles list ./mongofiles get testfile.zip ./mongofiles Delete testfile.zip  VerificationMd5  mg5sum testfiles.zip  at this time login mongo,show tables can see the new 2 files Fs.files and fs.chunks.  view the contents of Fs.files  www.2cto.com   db.fs.files.find ();  fs.files stores some basic meta-data information.  db.fs.chunks.find (); Some of the actual content data information is stored in the  fs.chunks.

Fixed collection of MongoDB (optimization efficiency)

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.