MongoDB Index on different types

旧时模样 提交于 2019-11-27 05:55:50

问题


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.


回答1:


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.

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



来源:https://stackoverflow.com/questions/4887727/mongodb-index-on-different-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!