mongodb:多键索引结构? [英] mongodb: Multikey indexing structure?

查看:235
本文介绍了mongodb:多键索引结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现很难理解mongodb中的多键是如何完成索引的。

I'm finding it hard to understand how exactly indexing is done on multikeys in mongodb.

这是我在其网站上读到的关于mongodb文档中的多键的内容:

1)在数组元素索引上创建索引会导致数据库索引数组的每个元素

2)...将索引文档中的所有标记,并为该文档创建X,Y和Z的索引条目。

This is what I read about multikeys in mongodb docs on its website:
1) "Creating an index on an array element indexes results in the database indexing each element of the array"
2) "...will index all the tags on the document, and create index entries for "X", "Y" and "Z" for that document."

那么该文档的索引条目究竟是什么意思?每个文档是否记住条目,在这种情况下,搜索将是一个全表扫描?或者它是与mysql相同的b-tree索引,其中每个索引条目将指向每个相应事件的多个文档,在这种情况下,我过度思考。

So what exactly does it mean by index entries for that document? Does each doc remember the entries, in which case searching is gonna be a full table scan? Or is it the same b-tree index of mysql where each index entry will point to multiple documents for each respective occurrence, in which case I'm over thinking too much.

让我们举一个例子:


obj1 = {

名称:Apollo,

text:Some关于阿波罗登月的文字,

标签:[月亮,阿波罗,太空飞行,美国国家航空航天局]

}


obj2 = {

名称:Atlantis,

text:关于亚特兰蒂斯飞行任务的一些文字,

标签:[space,atlantis,spaceflight,nasa]

}

> db.articles.ensureIndex({tags:1})

请帮我理解!谢谢,提前。

Please help me understand! Thanks, in advance.

推荐答案

在这种情况下,你的索引(它是一个B树)将如下所示: / p>

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 ]

这只是一个常规B树索引,除了每个文件可以出现多次(每个唯一标记值出现一次)。

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).

这篇关于mongodb:多键索引结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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