不同类型的MongoDB索引 [英] MongoDB Index on different types

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

问题描述

我们可以在同一个集合中拥有{data:hello},{data:123},甚至可以在其上创建索引。我很好奇mongodb如何管理幕后的索引。我们不能在不同类型上创建单个B树。对?但是,我做了getIndexes来查看是否创建了另一个索引但是只创建了一个索引。

We can have { data: "hello" }, { data: 123 } in the same collection and even create a index on it. I'm curious how does mongodb manage the index behind the scene. We can't create single B-tree on different types. Right? However, I did getIndexes to see if another index is created but only one index is created.

推荐答案

有两种类型没有问题在同一个索引中。索引中的每个键都包含类型。

There's no problem having two types in the same index. Each key within the index includes the type.

查询时,只返回与您查询的类型匹配的对象。

When you query, only objects matching the type you query on will be returned.

因此,如果您查询{data:hello},则只返回字符串等。

So if you query for {data: "hello"}, only strings will be returned, etc.

这篇关于不同类型的MongoDB索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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