I still can't understand how indexing a key of an embedded document really works.
Suppose I have the following collection of blog posts:
{
_id:0,
author: 'John Doe',
content: 'How indexing an embedded document work?',
comments:
[
{
sender:'Jane Doe',
content: 'I can\'t make it out either.'
},
etc...
]
},
etc...
Suppose I now set an index upon the sender property in the comments:
db.blog.createIndex({'comments.sender':1})
Now the question:
Does this mean that a big index is created for all elements ordered by sender in ascending order no matter in which array they are? Or an index is created for each array?
To make it clearer: when I do
blog.find({'comments.sender':'Jane Doe'}).toArray(function(err, array){})
Will it go through each blog post and look up each array till a record is found in that array and move to the next array in the next post? Or there is a big index, in which each record (ordered by sender) maps to the original array in which this match resides?