[MongoDB] Seven major implementation skills of MongoDB and seven major mongodb skills

Source: Internet
Author: User

[MongoDB] Seven major implementation skills of MongoDB and seven major mongodb skills
Tip 1: using the correct type to store data with the correct type is of great benefit. The data type affects the data query method, data storage sequence, and occupied space.
Number: The field used as a number is stored as a number. That is, the database automatically converts the overflow (for example, overflow caused by the $ inc operation) 32-bit floating point number to a 64-bit integer.
Date: a string in the yyy-mm-dd format in the first class. If the date type is used, it will always match to the millisecond level.
ObjectId must be stored as objectId. Do not save it as a string. This is very important because it is convenient to query the information contained in objectd. The vast majority of drivers obtain the document creation date from the method in use. The third objectId indicates that you need to occupy two more disk spaces. Tip 2: replace _ id with a simple and unique id. If the database does not use a unique field, use the default objetId for _ id. However, if the data itself has a unique field and does not require the objectId function, you can overwrite the default id with the unique one. Tip 3: Do not use documents as _ id except for the inevitable situation (mapreduce output). Generally, documents should not be used as _ id. The problem is that the fields in the index document are completely different from those in the index document. If there is no plan to query each sub-document each time, there will be Multiple indexes at last. Tip 4: Do not reference a database using a database. The general format is {$ id: primary key, $ ref: collectionName} (you can also have an optional $ db field, indicating the database ). If the referenced document set is determined, you can reference it only with _ id, which saves space compared with Id and set name. If you know the set to be referenced, database reference is a waste of space.
Tip 5: Do not use GridFS to process small binary data. GridFS needs to be queried twice to obtain the object metadata at one time and the content at another time. If GridFS is used to store small files, this doubles the number of application queries. Basically, GridFS is used to cut large binary objects into small pieces and store them in the database. Tip 6: handle the "seamless" failover assumption that a request is sent to the server, resulting in a network error. At this time, the driver has many options. If the driver knows that another server automatically sends a request to it? What if a network fault occurs after the driver sends the original request or the server sends a fault in response? The database may have processed the request and does not have to send it again. Tip 7. Handling the failure of the replication group and possible fault recovery: The application throws an exception "not master". Possible causes: 1. the replication group is performing fault recovery 2. The network condition is poor and the master node cannot be connected. 3. The application link node cannot be downgraded to a read-only node due to a problem.





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.