0

If I have a collection which I query based on fields _id and CreationTimestamp.O as below:

var _query = Query.And(
 Query.EQ("_id", "TheId"),
    Query.GT("CreationTimestamp.0", DateTimeOffset.UtcNow.AddMinutes(-15).UtcTicks));

Should I create a compound index on both these fields? I know _id by default has an index.

I am looking for guidance on best practice i.e. Create a compound index for both fields or just create an index for CreationTimestamp.O as their is already an index on _id

4

1 回答 1

3

在这里创建复合索引没有太多好处。由于字段上自动创建的索引的选择性_id是 1(它是唯一索引),因此没有理由将任何复合索引作为前缀。唯一可能的好处可能是 MongoDB 可以为此查询使用覆盖索引并可能加快处理速度(您需要对数据进行基准测试以证明这一点)。

于 2012-05-29T14:23:15.337 回答