In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
What are the problems of MongoDB BSON format? I believe many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problems. Through this article, I hope you can solve this problem.
In this paper, we start with several problems, analyze and understand some features of MongoDB's BSON format and matters needing attention when using it.
What are the problems with MongoDB BSON format
Question 1: strings and numbers
{a:12}
{abank 12'}
Which takes up more space?
{a:1234}
{abank 1256'}
Which takes up more space?
For the first example, it should be the former that takes up more space, and for the second, the latter. The specific reason is: MongoDB is divided into two levels of digital storage, a 32-bit, one is 64-bit, such as our example above, are within the range of 32-bit expression, so the numeric type occupies 4 bytes, while the string type takes up space for its length plus the last bit Terminator. So the string takes up 3 bytes in the first example and 5 bytes in the second example.
The same is true in the index, but it is worth noting that strings and numbers are not sorted in the same way, so in indexing, numbers are compared as numbers, and strings are compared as strings. For example, in a string,'12'is less than'2'.
Question 2: objects and arrays
{a:1,b:2,c:3}
{d: [1,2,3]}
Which takes up more space?
You may think it is the first one because it looks longer, or you may think it contains the key value of each field. When in fact?
The answer is that the second takes up more space, because the BSON data structure is similar to an object when storing array types, such as the storage of the second item is actually equivalent to this:
{d: {0:1,1:2,2:3}}
What are the problems with MongoDB BSON format
Ordering of question 3:_id and $natural
There is a special sort method in MongoDB called $natural. When you specify to sort by $natural, it is equivalent to sorting by the order in which the data is organized on disk. When you sort by the automatically generated _ id field, it is equivalent to sorting by insertion time. When no sort order is specified, MongoDB is sorted by $natural. Is there any difference between the two? Shouldn't the insertion order be the same as the order in which the data is organized? The answer is: yes.
When there is a change in the data in the MongoDB, it may cause the data to move, for example, you first write 1000 pieces of data in the following way:
For (var iTuno Bandi)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.