我想在以下位置获取行:
{repair field has "ac" OR {repair is "tv" and phone field in range 1091-1100}}
我正在尝试以下查询:
type M map[string]interface{}
conditions := M{"name": M{"$regex": "me"},
"$or": []M{M{"repair": M{"$eq": "ac"}},
"$and": []M{M{"repair": M{"$eq": "tv"}}, M{"phone": M{"$gte": 1091, "$lte": 1100}}}}}
fmt.Println(conditions)
err = c.Find(conditions).Sort("phone").Limit(20).All(&j)
但是,我遇到了一个编译错误:
index must be non-negative integer constant
cannot use []M literal (type []M) as type M in array or slice literal.
最佳答案
关于MongoDB 在 golang 中使用 $or 和 $and 的组合查找查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46194546/