PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 2, 2022

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

 November 02, 2022     indexing, mongodb     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing