我正在嘗試使用 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
1 回答

繁華開滿天機
TA貢獻1816條經驗 獲得超4個贊
嘗試:
q := bson.M{
"btId": neighbour.BtId,
"timestamp": bson.M{
"$gt": sensorDataStartPoint.Timestamp,
"$lt": sensorDataStartPoint.Timestamp.Add(time.Second * 3000),
},
}
沒有必要使用,$and因為這是 MongoDB 查詢的默認設置。
另請注意,如果有必要使用$and預期的參數,則有一個數組,而不是一個映射!
- 1 回答
- 0 關注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消