1

I am running a fairly simply query where I am looking for the count of snapshots on Tasks between a certain time frame. Assuming dates d1, d2 and d3 where d1 < d2 < d3 I would expect that the count of snapshots between d1 inclusive and d2 exclusive plus the count of snapshots between d2 inclusive and d3 exlusive should be equal to the count of snapshots between d1 inclusive and d3 exclusive. However, I am consistently getting different counts... the count between d1 and d3 is larger than the sumation of the individual queries.

---- CASE 1: 01/13 – 01/15 Input

{
find:{
      "_TypeHierarchy":"Task",
      "_ValidFrom":{"$gte" : "2013-01-13T00:00:00.000Z"},
      "_ValidTo":  {"$lt"  : "2013-01-15T00:00:00.000Z"}},
fields:["_id","ObjectID","_SnapshotNumber","_ValidFrom","_ValidTo"],
pagesize:1
}

Output

"TotalResultCount": 559,

---- CASE 2: 01/13 – 01/14 Input

{
find:{
      "_TypeHierarchy":"Task",
      "_ValidFrom":{"$gte" : "2013-01-13T00:00:00.000Z"},
      "_ValidTo":  {"$lt"  : "2013-01-14T00:00:00.000Z"}},
fields:["_id","ObjectID","_SnapshotNumber","_ValidFrom","_ValidTo"],
pagesize:1
}

Output

"TotalResultCount": 52,

---- CASE 3: 01/14 – 01/15 Input

{
find:{
      "_TypeHierarchy":"Task",
      "_ValidFrom":{"$gte" : "2013-01-14T00:00:00.000Z"},
      "_ValidTo":  {"$lt"  : "2013-01-15T00:00:00.000Z"}},
fields:["_id","ObjectID","_SnapshotNumber","_ValidFrom","_ValidTo"],
pagesize:1
}

Output

"TotalResultCount": 498,
johnr
  • 98
  • 6
Heather K
  • 61
  • 3
  • In studying the resulting data, the output now makes sense. Any snapshots that span d2 will not be returned in the second and third query. To get the results I wanted, I should have simply only used _ValidFrom in my Find clause. – Heather K Feb 06 '13 at 17:17

1 Answers1

2

In studying the result objects, I now see my mistake. If you want to find the count of snapshots in a given timeframe, you should specify the start and end time and the inequalities in the _ValidFrom clause:

"_ValidFrom":{"$gte" : "2012-01-13T00:00:00.000Z", "$lt"  : "2012-01-14T00:00:00.000Z"}},

In the orginal question, the query in case 2 and case 3 wouldn't include a snapshot where ValidFrom was after d1 and ValidTo was after d2 but prior to d3. However the first case would. Hence the total count being higher for case 1 than case 2 and case 3 combined.

Heather K
  • 61
  • 3