0

I do much find requests on collection like this:

{'$and': [{'time': {'$lt': 1375214400}},
          {'time': {'$gte': 1375128000}},
          {'$or': [{'uuid': 'test'},{'uuid': 'test2'}]}
         ]}

Which index i must create: compound or two single or both?

uuid - name of data collector. time - timestamp

I want to retrieve data, collected by one or few collectors in specified time interval.

4

1 回答 1

2

$and如果没有and 使用$in而不是,您的查询会更好地编写$or

{
  'time': {'$lt': 1375214400, '$gte': 1375128000},
  'uuid': {'$in': ['test', 'test2']}
}

那么很明显,您需要一个涵盖两者timeuuid获得最佳查询性能的复合索引。但重要的是始终通过使用explain().

于 2013-07-30T14:02:44.400 回答