Does field type matter in a MongoDB index?

后端 未结 2 487
挽巷
挽巷 2020-12-17 10:44

Here are two examples of a document structure in MongoDB.

{  
 UserId: \"123\",  
 UserName: \"Usain Bolt\"  
}



{  
 UserId: NumberLong(123),  
 UserName:         


        
2条回答
  •  心在旅途
    2020-12-17 11:24

    I don't have a specifically accurate answer on the matter, but here is my understanding:

    Indexes

    Indexed fields may be of any type, including (embedded) documents

    Indexes are mostly likely hashed, regardless of the type, to be able to index the same way. If there were specific considerations to be observed for different types, the standard mongodb docs would make that distinction.

    The answer given to a similar question here refers to code samples from mongodb, that suggests the index comparisons are pretty much the same regarding types, but probably performance geared towards the size of the index.

提交回复
热议问题