Mongodb fixed collection (CappedCollection) and big file management (GridFS)

Source: Internet
Author: User
CappedCollection to view the collection status information db. cot1.stats (); view the status information of cot1 to delete the specified database. collection1.drop (); the default value of centralized creation for Delete collection1 collection mongoDB is implicitly created. You can use createCollection to display the creation of a collection db. createCollection (collect );

CappedCollection to view the collection status information db. cot1.stats (); // view the status information of cot1 in the collection. Delete the specified database. collection1.drop (); // you can use createCollection to display and create a collection database. createCollection ("collect ");

Capped Collection

View the collection status information db. cot1.stats (); // view the status information of cot1 in the collection. Delete the specified database. collection1.drop (); // you can use createCollection to display and create a collection database. createCollection ("collect"); deletes the specified database. dropDatabase (); // Delete the current database query all databases show dbs // query all databases to display all the collections show tables in the current database; or show collections;

Features of a fixed set

Fixed Set attributes and usage:

Attribute 1: Fast insertion of fixed sets

Attribute 2: Query output in the insert order is extremely fast

Usage 1: store log information

Usage 2: cache a small number of documents

Create a fixed set

Eg. db. createCollection ("collect", {capped: true, size: 10000 });

When you create a capped collection, you can specify the maximum number of documents that can be stored in the collection. However, you must specify the size because you always check the size before checking maxRowNumber. you can use validate () to check the space used by a collection, and then set the size to a large value.> db. createCollection ("mycappedcoll", {capped: true, size: 10000, max: 100}) {"OK": 1}> db. mycappedcoll. validate (); when you create a collection, there is also a parameter "autoIndexID", which can be "true" and "false" to determine whether to create an index on "_ id, for example,> db. createCollection ("mycappedcoll", {capped: true, size: 10000, max: 100, autoIndexId: false}) by default, indexes are created for General collections, however, capped collection is not created. capped collection cannot be Shard, which also makes sense. Sharding is not significant for a table that is often refreshed and of fixed size.

Conversion set

To convert a common set to a fixed set, use the convertTocapped command.

Db. runCommand ({convertTocapped: "test", size: 10000 });

Natural sorting

Db. mycappedcolt. find (). sort ({"$ natural": 1 });

Determines whether a set is a fixed set.

Db. colt. isCapped ();

View Collection status information

Db. colt. stats ();

GridFS

GridFS can avoid file system problems when users upload content.

GridFS does not generate disk fragments

GridFS Storage Data

GrdiFS uses two tables to store data:

Files contains metadata objects

Chunks binary block that contains other related information.

You can change the prefix of a third-party language.

Use GridFS Program Files

Eg .. /program files put testfile.zip. /program files list. /program files get testfile.zip. /Program Files delete testfile.zip verify md5mg5sum testfiles.zip at this time, log on to mongo, show tables, you can see two new files fs. files and fs. chunks. view fs. files content db. fs. files. find (); fs. files stores some basic metadata information. db. fs. chunks. find (); fs. chunks stores some actual content data information.

For more information, see [].

, Hong Kong Server rental, Hong Kong server, Hong Kong Virtual Host

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.