如何使用mgo包编写以下查询:
a:{$subtract:[variable,'$created']}
我试过
date := time.Now()
bson.M{
"a":bson.M{
"$subtract":bson.M{date,"$created"}
}
}
但是bson.M是一张地图,并要求我提供钥匙;(
答案 0 :(得分:1)
问题是数组会包含time.Time
结构和string
,所以它是混合类型数组...但我想我找到了答案:How to represent an array with mixed types
type list []interface{}
date := time.Now()
sub := list{date, "$created"}
bson.M{
"a":bson.M{
"$subtract":sub
}
}