Reputation: 103
MongoDB can store documents with different fields in one collection. How then indexes will work? If I create index on field that presents not in all documents, the documents which don't have that will not be indexed?
Upvotes: 2
Views: 160
Reputation: 33175
Documents without the field in an index will be indexed as having no value for that field. You probably want to review this: http://docs.mongodb.org/manual/core/indexes/
If you want to not include documents that don't have the key in the index, you can use a sparse index: http://docs.mongodb.org/manual/administration/indexes/#sparse-indexes
Upvotes: 1