Wednesday, November 2, 2022

[FIXED] How to Create a nested index in MongoDB?

Issue

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

B. How do I index valuetwo?

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

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.


Solution

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

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

You do need to explicitly create indexes on each field.



Answered By - Bryan Migliorisi
Answer Checked By - Robin (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.