indexing - How to Create an index of a key in a map or item in a list in MongoDB -


the following questions refer example.

  1. how create index ids in idsandnames map?

    i want search these numbers: 7065362, 7064458, 7065003, 7064286...

  2. how create index strings in subtargets list?

    i want search these strings: all, action, drama...

my example:

{     "_id" : objectid("sdfsdfsdfsdfsdfsd910d41ad9"),     "targets" : {         "superheroes" : {             "idsandnames" : {                 "7065362" : "doctor strange",                 "7064458" : "dr. manhattan",                 "7065003" : "captain atom",                 "7064286" : "hulk"             },             "subtargets" : [                  "all",                 "action",                 "drama"             ]         }         "bestsuperheroes" : {             "idsandnames" : {                 "7065362" : "superman",                 "7064458" : "thor",                 "7065003" : "professor x",                 "7064286" : "batman"             },             "subtargets" : [                  "all",                 "scifi",                 "chickflicks"             ]         }             } ... } 

before trying create index maybe should review schema, changing like:

... "superheores" : [  {     "id": "7065362",     "name": "doctor strange"   }]  

so can use db.collection.ensureindex({'targets.superheroes.id': 1});. won't able create effective index if have dynamic key names.

and text, try the text search index.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -