字段类型在MongoDB索引中是否重要? [英] Does field type matter in a MongoDB index?

查看:377
本文介绍了字段类型在MongoDB索引中是否重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是MongoDB中文档结构的两个示例。

  {
UserId:123,
用户名:Usain Bolt
}



{
UserId:NumberLong(123),
用户名:Usain螺栓
}

如果我要在上创建索引UserID ,上述两个示例之间查找查询性能会有区别吗?

解决方案

我没有关于此事的具体准确答案,但这是我的理解:



索引


索引字段可以是任何类型,包括(嵌入式)文件


索引很可能是散列的,无论类型如何,都能够以相同的方式编制索引。如果对不同类型有特定的考虑因素,那么标准的mongodb文档会做出这种区分。



给出是指来自mongodb的代码示例,这表明索引比较在类型方面几乎相同,但可能是针对索引大小的性能。 / p>

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?

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.

这篇关于字段类型在MongoDB索引中是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆