Mongodb query does not use prefix on compound index with text field

后端 未结 2 1539
刺人心
刺人心 2021-01-14 06:48

I\'ve created the following index on my collection:

db.myCollection.createIndex({
  user_id: 1,
  name: \'text\'
})

If I try to see the exe

2条回答
  •  难免孤独
    2021-01-14 07:24

    This behavior is due to text indexes being sparse by default:

    For a compound index that includes a text index key along with keys of other types, only the text index field determines whether the index references a document. The other keys do not determine whether the index references the documents or not.

    The query filter is not referencing the text index field, so the query planner won't consider this index as it can't be certain that the full result set of documents will be returned by the index.

提交回复
热议问题