Optimization of Mongodb Index?

  mongodb, question

It is not clear that there is no optimization in the index village. There is no in-depth understanding of indexes. By the way, help me explain it!

1. Each piece of data has geographical information. (province, city), then I set up the index:


My doubt is, when this was established, was there no data to establish an index value or was it established by the index value?

For example, there is such data
 id name         city         area
 1  zhangsan     beijing      beijing
 2  lisi         shanghai     shanghai
 3  zhaowu       beijing      beijing
 # Each piece of data is created
 city->shanghai -> 2
 # or according to the index value
 city->beijing--|-> 1
 |-> 3

Thank you

I didn’t fully understand your question. I probably understood it as follows:

1. MongoDB’s indexes are mostly B-Tree indexes; In addition,

1) hasindex, mainly used for hashed sharding
 2)Geospatial index, such as 2d and 2dsphere, is essentially implemented by B Tree in MongoDB
 3)Text index

2. The B Tree is sorted and saved according to the index value and points to the storage location of the corresponding Collection.

3. To extend a bit, WiredTiger at the bottom of MongoDB currently uses a Log-Merged Structure Tree to optimize write performance.

The index of MongoDB can learn more about the above contents. For reference.

Love MongoDB! Have fun!