mongodb: Multikey indexing structure?

我只是一个虾纸丫 提交于 2019-12-03 02:01:37

In this case, your index (which is a B-tree) would look like this:

 apollo => [ obj1 ]
 atlantis => [ obj2 ]
 moon => [ obj1 ]
 nasa  => [ obj1, obj2 ]
 space => [ obj2 ]
 spaceflight => [ obj1, obj2 ]

This is just a "regular" B-tree index, except that every document can appear more than once (it appears once for every unique tag value).

I think you misunderstood the difference between Multiindex and Compound indexes:

Compound indexes are user-defined indexes for multiple fields at once. Multykey indexes: MongoDB determine if the field on which the Index is released is an array and create an index for each of the array elements, for example

db.user.ensureIndex({"address.street":1});

In this case and because the target field is an Array the index will store all the items but only once.

I highly recomend you to take a look at this simple articlw that will clarify you doubts about simple imdex types in MongoDB: http://mongodbspain.com/en/2014/01/24/mongodb-indexes-part1/

Regards,

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