NoSQL: indexing and keyword-based searching NoSQL: indexing and keyword-based searching mongodb mongodb

NoSQL: indexing and keyword-based searching


In MongoDB an index on tags would be done by utilizing the multi-keys feature whereby the database tries to match documents against each element of an array. You would index this tags attribute of a given document which would create a btree that is constructed out of ranges of tags in that array.

You can learn more about multikeys here and can get more information about indexing in MongoDB by watching this presentation: MongoDB Internals

Does the secondary index only store the item/object id or more?

The indexes consist of the indexed field (lets say it's a tags array in your case, then the field would be a single tag) and an offset used to efficiently locate the document in memory. It also has some padding + other overhead as described here

If a query contains k tags, are k subqueries - one for each tag - executed and the k partial results are combined one the initiating node?

It depends, but if, for example, the query were using an $or on the tag field I think the queries are performed in parallel, each in O(log n) time, and the results are combined to form the result set but I'm not sure about this though.