我正在使用"go.mongodb.org/mongo-driver/bson"
有没有办法能够禁用字段,但仍然是有效的 bson 映射?
publishFilter := bson.M{}
if publishedOnly {
publishFilter = bson.M{"published": true}
}
pipeline := []bson.M{
{"$sort": bson.M{"_id": -1}},
{
"$match": bson.M{
"_id": bson.M{
"$gt": sinceObjectID,
"$lte": maxObjectID,
},
publishFilter, // I want to control this to be nothing or `{"published": true}`
// depending on `publishedOnly`
},
},
{"$limit": query.Count},
}
这段代码绝对不能编译Missing key in map literal
慕沐林林
相关分类