Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

50 suggestions for MongoDB developers Tip15

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This series of articles are translated from "50 Tips and Tricks for MongoDB Developers". I can't find the Chinese version for the time being. Anyway, I have been studying mongodb deeply recently, so I just want to translate it. On the one hand, enhance the effect of our own learning, on the other hand, let the big family to experience what we mongodb users need to pay attention to.

First of all, I declare that my English level is not too high, and some English translation into Chinese can not find suitable words to express, so the original English words may appear in the article, or the translation in some places will be a little blunt, that is to say, there will be literal translation. The main purpose of translating this book is for everyone to learn and explore. If there is any inaccuracy in translation, or if there is a more accurate translation, please point out that I will correct it in time. Thank you in advance.

Tip#15.Override _ id when you have your own simple,unique id

You can override the internal _ id when your data has a simple, unique primary key

If your data doesn't have a custom primary key, use the default ObejctId. However, if your data has its own primary key, then you do not need ObjectId, you can use your custom primary key to override the internal ObjectId. This saves space on bit, which is especially useful when indexing your primary key, because it saves indexing space and resources (which is important when saving data).

There are two reasons why your own primary key does not apply to you:

1. You must make sure that your primary key is unique and includes a mechanism for handling duplicate primary keys.

two。 You must remember the tree structure of the index and how to insert data immediately and non-randomly.

As far as index trees are concerned, ObjectId performs well in insertion order, and they are always self-increasing, meaning that the data is always placed on the right leaf of the B-tree. Mongodb only needs to keep the right side of the B-tree in memory.

Conversely, if the _ id column is a random value, it means that _ id will be inserted everywhere in the tree. You need to put the entire index page in memory, update a small part, and may ignore it until it slips out of memory again. It is inefficient to do so.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report