"MongoDB" MongoDB seven great implementation tips

Source: Internet
Author: User
Tags unique id

Skill one, using the right typestoring data with the right type is a great boon. Data types affect the way data is queried, the order in which data is stored, and how much space is occupied.
numbers: Fields used for numbers are stored numerically. A field that is calculated or sorted by sizeThe database automatically converts a 32-bit floating-point number that overflows (such as an overflow due to a $inc operation) and turns it into a 64-bit integer.
Date: Class A string in YYY-MM-DD form is available, if the date type will always match to the millisecond level
Objectid will be stored as objectid, and never be saved as a string. This is very important because the convenience of query two is the information contained in the OBJECTD, the overwhelming majority of drivers are obtained from the method of the creation date of the document. The third Objectid represents two more disk space to accompany. Tip Two: replace _id with a simple unique ID if the database doesn't have a unique field, use the default Objetid to do _id. But if the data itself has a unique field and does not require Objectid functionality, then it is better to overwrite the default ID with its own unique one.Three, do not use the document to do _idIn addition to the unavoidable situation (the output of MapReduce), the document should not normally be used as a _id. The problem is that indexing a document with fields and index documents is completely different. If you do not have a schedule for each subdocument, you will end up with multiple indexes. tip Four, do not use database referencesthe general form of a database reference is: {$id: Primary key, $ref: CollectionName} (optionally $db field, which represents the database). If the referenced document collection is deterministic, it may be useful to use only _id references, which saves space compared to the ID and collection names. If you know the collection to be referenced, the database reference is a waste of space.
technique Five, do not use GRIDFS to process small binary dataGridfs need to query two times, one time to get the meta-information of the file, and another time to get content, so if you use Gridfs to store small files, it will double the number of application queries. Fundamentally, Gridfs is used to cut large binary objects into small pieces that exist in the database. Technique six, processing "seamless" failover assumptions sent to the server a request, got a network error, then the driver has a lot of options. If the driver knows if another server is automatically sending a request to it? What if a network failure occurs after the driver sends the original request, or when the server responds with a fault? The database may have processed the request and it will not have to be sent again. Seven, dealing with replication group failure and possible failure recovery: App throws exception "not master" exception possible cause: 1. Replication group is recovering 2, network condition is not good, cannot link the main node. 3. There is a problem with the app link node and cannot be downgraded to a read-only node.





"MongoDB" MongoDB seven great implementation tips

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.