indexing - How to Create an index of a key in a map or item in a list in MongoDB -
the following questions refer example.
how create index ids in idsandnames map?
i want search these numbers: 7065362, 7064458, 7065003, 7064286...
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
Post a Comment