如何在MongoDB中创建嵌套索引? [英] How to Create a nested index in MongoDB?

查看:703
本文介绍了如何在MongoDB中创建嵌套索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个。如何索引嵌套及其所有值?

A. How do I index "nested" and all of it's values?

B.我如何索引valuetwo?

B. How do I index valuetwo?

{
    id: 00000,
    attrs: {
        nested:{
            value: value1,
            valuetwo: value2,
        }
    }
}

我看过这里: http:// www.mongodb.org/display/DOCS/Indexes ,以及据我所知的文档,不清楚索引未嵌套的东西。

I've looked here: http://www.mongodb.org/display/DOCS/Indexes, and the docs to my knowledge, aren't clear about indexing things that aren't nested.

推荐答案

您创建它们就像在顶级字段上创建索引一样:

You'd create them just as if you were creating an index on a top level field:

db.collection.ensureIndex({"attrs.nested.value": 1})

您需要在每个字段上显式创建索引。

You do need to explicitly create indexes on each field.

这篇关于如何在MongoDB中创建嵌套索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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