我正在尝试使用mgo lib创建查询。
q := bson.M{
"$and": bson.M{
"btId": neighbour.BtId,
"timestamp": bson.M{
"$gt": sensorDataStartPoint.Timestamp,
"$lt": sensorDataStartPoint.Timestamp.Add(time.Second * 3000),
},
},
}
因此,这呈现为,map[$and:map[btId:BTR0102 timestamp:map[$gt:2012-04-11 19:08:59 +0200 CEST $lt:2012-04-11 19:58:59 +0200 CEST]]]
但是$and expression must be a nonempty array
在尝试执行查询时出现错误
它应该是 : btId = "123" AND timestamp > sensorDataStartPoint.Timestamp AND timestamp < sensorDataStartPoint.Timestamp + 3000s
谢谢
尝试:
q := bson.M{
"btId": neighbour.BtId,
"timestamp": bson.M{
"$gt": sensorDataStartPoint.Timestamp,
"$lt": sensorDataStartPoint.Timestamp.Add(time.Second * 3000),
},
}
无需使用,$and
因为这是MongoDB查询的默认设置。
另请注意,如果有必要使用$and
预期的参数,则有一个数组,而不是一个映射!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句