Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
968 views
in Technique[技术] by (71.8m points)

performance - Does field type matter in a MongoDB index?

Here are two examples of a document structure in MongoDB.

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



{  
 UserId: NumberLong(123),  
 UserName: "Usain Bolt"  
}

If I were to create an index on UserID, would there be a difference in find query performance between the above two examples?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...