MongoDB Index on different types

后端 未结 1 1311
暖寄归人
暖寄归人 2020-12-10 13:20

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\

相关标签:
1条回答
  • 2020-12-10 13:47

    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.

    0 讨论(0)
提交回复
热议问题