1
我有這樣那樣的查詢:合成指數MongoDB的使用排序和範圍
db.contacts.find({createdAt: {$gte: 1458585000000, $lte: 1461349799000},
asset_type: "personal",
createdBy: "pxedNoPZzGAdx2fnK",
status: "done"})
.sort({createdAt: -1})
是否可以寫這類查詢包括範圍和排序的一個複合索引?
我創建了一個複合索引,例如:
contacts._ensureIndex({createdAt: 1, asset_type: 1, createdBy: 1, status: 1});
請問這個複合索引的工作?
該索引應該可以工作,但使用['explain'](https://docs.mongodb.org/manual/reference/method/cursor.explain/)進行確認。 – JohnnyHK
順便說一句:不知道你的陳述是否正確,我不明白你爲什麼在'ensureIndex'之前使用下劃線......不應該是:'db.contacts.ensureIndex({createdAt:1,asset_type:1,createdBy :1,status:1})'而不是? –