最近项目中用到,记录一下查询方法
具体用法如下:
filter := bson.M{}
if electricity == "电量小于等于20" {
filter["electricity"] = bson.M{
"$elemMatch": bson.M{
"$lte": 20,
}}
}
if electricity == "电量小于等于50" {
filter["electricity"] = bson.M{
"$elemMatch": bson.M{
"$lte": 50,
}}
}
total, err = app.Mgo.QueryPaging(ctx, CollNameTempDevice, filter, bsonx.Sort("created_at", true), page, size, &ps)