In MongoDB how do you index an embedded object fields in an array?

You can create the following index :

db.posts.ensureIndex({"comments.author" : 1})

This will index only the author field of the embedded documents. Note that the index will be used for

db.posts.find( { "comments.author" : "julie" } )

As well as

db.posts.find( { comments: {$elemMatch: {author : "julie" }}} )

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)