When it comes to indexing arrays, MongoDB indexes each value in the array, so you can query for individual elements, such as red. For example:
> db.col1.save({'colors': ['red','blue']}) > db.col1.ensureIndex({'colors':1}) > db.col1.find({'colors': 'red'}) { "_id" : ObjectId("4ccc78f97cf9bdc2a2e54ee9"), "colors" : [ "red", "blue" ] } > db.col1.find({'colors': 'blue'}) { "_id" : ObjectId("4ccc78f97cf9bdc2a2e54ee9"), "colors" : [ "red", "blue" ] }
For more information, check out MongoDB documentation on Multikeys: http://www.mongodb.org/display/DOCS/Multikeys
Charles Hooper Oct 30 '10 at 20:01 2010-10-30 20:01
source share