0
votes

From the MongoDB documentation they have stated six index types :

  1. Single Field Index
  2. Compound Index
  3. Multikey index
  4. Geospacial index
  5. Text index
  6. Hashed index

The documentation has also stated four index properties.

  1. Unique Indexes
  2. Partial indexes
  3. Sparse Indexes
  4. TTL Indexes

My questions are:

  1. Can any index type have any index property?

  2. Can an index type have more than one index property?

  3. According to the docs: MongoDB creates a unique index on the _id field during the creation of a collection. Does this mean when I search by Id MongoDB does not do a collection scan but instead uses the id index to execute the query efficiently? Or is the default id index just for uniqueness only? Does a unique index property always support faster queries?

  4. I am using MongoDB via mongoose. When defining a schema in node.js does the field unique: true imply indexing of that will result to efficient search as opposed to a collection scan?

  5. Can materialized views be indexed in MongoDB? If so how?

  6. In the MongoDB documentation it states that MongoDB provides a number of different index types to support specific types of data and queries. Gut there is no explanation of what index properties are. How would you define index properties?

1

1 Answers

1
votes

Can any index type have any index property?

Can an index type have more than one index property?

You can test yourself and find out.

Does this mean when I search by Id MongoDB does not do a collection scan but instead uses the id index to execute the query efficiently?

Yes.

Does a unique index property always support faster queries?

Uniqueness refers to a restriction on data which can be placed in the field which is indexed. Both unique and non-unique indexes allow fast retrieval of data queried by indexed fields.

Can materialized views be indexed in MongoDB?

If you are talking about https://docs.mongodb.com/manual/core/materialized-views/, "materialized views" in MongoDB are orthogonal to indexes. You can add indexes on what this page refers to as "output collection" (the argument to $merge) if you wish to query the "materialized view" efficiently.

MongoDB provides a number of different index types to support specific types of data and queries.

Geospatial index supports geo queries. Text index supports text search. Other indexes are general-purpose.