Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个类似于以下的查询
find( { a : { $gt: 3 } } ).sort( { b : -1 } )
是否建议分别为字段 a 和 b 创建索引?
不,使用复合索引查询会更快:
db.items.ensureIndex({a:1, b:-1});
您还可以确保您的查询使用带有解释命令的索引。