我想在 mongodb 的许多领域进行搜索。这是我到目前为止所做的var filter bson.Dfilter = append(filter, bson.E{"title", primitive.Regex{Pattern: "input", Options: "i"}})filter = append(filter, bson.E{"author", primitive.Regex{Pattern: "input", Options: "i"}})filter = append(filter, bson.E{"content", primitive.Regex{Pattern: "input", Options: "i"}})cur, err := p.postProposalCollection.Find(ctx, filter)但是它是AND这样工作的WHERE title ~ 'input' AND author ~ 'input' AND content ~ 'input'我希望它像这样工作WHERE title ~ 'input' OR author ~ 'input' OR content ~ 'input'
1 回答
UYOU
TA贡献1878条经验 获得超4个赞
也许你可以直接使用$orand$regex
filter := bson.M{
"$or": bson.A{
bson.M{"title": bson.M{"$regex": "input"}},
bson.M{"author": bson.M{"$regex": "input"}},
bson.M{"content": bson.M{"$regex": "input"}},
},
}
p.postProposalCollection.Find(ctx, filter)
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报
0/150
提交
取消