【发布时间】:2019-04-23 18:03:05
【问题描述】:
我在 mongodb 中创建复合索引时,发现了一个奇怪的行为。 我创建了一个索引:
db.getCollection('Subject').createIndex({a:1, b:2, c:3})
它创建了一个名为 a_1_b_2_c_3 的索引。
现在当我使用 mongo find 命令时:
db.getCollection('Subject').find({a:1, b:2, c:3}) //it works fine `a_1_b_2_c_3` is used.
db.getCollection('Subject').find({a:1, b:2}) //this also works fine `a_1_b_2_c_3` is used.
db.getCollection('Subject').find({a:1, c:2}) //this also works fine `a_1_b_2_c_3` is used.
db.getCollection('Subject').find({b:1, c:2}) //But this command doesn't uses the index `a_1_b_2_c_3`.
谁能告诉我为什么会发生这种行为?
【问题讨论】: