I'm trying to query a timestamp that is between two other timestamps. I've got this simple function:
func (e *EventService) GetEmployeeEventsBetween(employeeID string, start, end int64) ([]Event, error) {
var retrivedEvents []Event
if err := e.c().Find(bson.M{
"employee": employeeID,
"start": bson.M{"$gte": start, "$lte": end},
}).All(&retrivedEvents); err != nil {
return nil, err
}
return retrivedEvents, nil
}
Now according to that function the query should only return "events"
that start date timestamp is greater than the start
timestamp passed in and less than the end
timestamp passed in.
However let's say the db has 3 events each with these start dates:
1474290000
1474389000
1474463700
Now lets say I pass in a start
param of 1474462800
and end
param of 1474491600
I would expect that function would only return 1 "event"
which would be the one with the 1474463700
timestamp however it returns all of them. Pretty much no matter what I pass in as my start
and end
params it returns all the items in the db
UPDATE:
If I log .Explain()
this is what I get back
bson.M{
"queryPlanner": bson.M{
"plannerVersion":1,
"namespace":"hairbuddy.events",
"indexFilterSet":false,
"parsedQuery": bson.M{
"$and":[]interface {}{
bson.M{
"employee": bson.M{"$eq":"57c36bdfe5b07e10ae5526ee"}
},
bson.M{
"start":bson.M{"$lte":1474491600}
},
bson.M{
"start": bson.M{"$gte":1474462800}
}
}
},
"winningPlan": bson.M{
"inputStage": bson.M{
"stage":"COLLSCAN",
"filter": bson.M{
"$and":[]interface {}{
bson.M{
"employee": bson.M{"$eq":"57c36bdfe5b07e10ae5526ee"}
},
bson.M{
"start": bson.M{"$lte":1474491600}
},
bson.M{
"start":bson.M{"$gte":1474462800}
}
}
},
"direction":"forward"
},
"stage":"LIMIT",
"limitAmount":40
},
"rejectedPlans":[]interface {}{}
},
"executionStats": bson.M{
"totalDocsExamined":3,
"executionStages": bson.M{
"restoreState":0,
"isEOF":1,
"invalidates":0,
"inputStage": bson.M{
"restoreState":0,
"direction":"forward",
"stage":"COLLSCAN",
"executionTimeMillisEstimate":0,
"works":5,
"needYield":0,
"nReturned":1,
"advanced":1, "isEOF":1,
"docsExamined":3,
"filter": bson.M{
"$and":[]interface {}{
bson.M{
"employee": bson.M{"$eq":"57c36bdfe5b07e10ae5526ee"}
},
bson.M{
"start": bson.M{"$lte":1474491600}
},
bson.M{
"start": bson.M{"$gte":1474462800}
}
}
},
"needTime":3,
"saveState":0,
"invalidates":0
},
"stage":"LIMIT",
"advanced":1,
"needYield":0,
"saveState":0,
"limitAmount":40,
"nReturned":1,
"executionTimeMillisEstimate":0,
"works":5,
"needTime":3
},
"allPlansExecution":[]interface {}{},
"executionSuccess":true,
"nReturned":1,
"executionTimeMillis":0,
"totalKeysExamined":0
},
"serverInfo": bson.M{
"version":"3.2.7",
"gitVersion":"4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2",
"host":"rodrigos-MacBook-Pro.local",
"port":27017
},
"ok":1,
}