$ne使用golang(mgo)检查MongoDb中的两个字段
我在后端使用go lang,并将mongoDB用作我的数据库。在我的mgo管道中,我从我的mongoDB中选择了一些值。下面是正在工作的go-lang等效条件$ne使用golang(mgo)检查MongoDb中的两个字段,mongodb,go,mgo,Mongodb,Go,Mgo,我在后端使用go lang,并将mongoDB用作我的数据库。在我的mgo管道中,我从我的mongoDB中选择了一些值。下面是正在工作的go-lang等效条件 if status !="Processing"{ //then select or project the values } mgo查询如下所示,这是可行的 pipe10 := c.Pipe([]bson.M{ { "$unwind": "$" + type,
if status !="Processing"{
//then select or project the values
}
mgo查询如下所示,这是可行的
pipe10 := c.Pipe([]bson.M{
{
"$unwind": "$" + type,
},
{
"$match": bson.M{
type + ".status": bson.M{
"$ne": "Processing",
},
},
},
{
"$project": bson.M{
"name": 1,
},
},
},
)
但是,当我尝试为$ne添加另一个值时,这是不起作用的。这不会抛出错误,只是跳过了它!=条件
下面是go-lang等效条件,我需要执行该条件,但不起作用
if status !="Processing" || status !="Denied{
//then select or project the values
}
我在mgo试过如下
1. pipe10 := c.Pipe([]bson.M{
{
"$unwind": "$" + type,
},
{
"$match": bson.M{
type + ".status": bson.M{
"$ne":[]interface{"Processing","Denied"}
},
},
},
{
"$project": bson.M{
"name": 1,
},
},
},
)
2. pipe10 := c.Pipe([]bson.M{
{
"$unwind": "$" + type,
},
{
"$match": bson.M{
type + ".status": bson.M{
"$ne":bson.M{
"$in":[]interface{"Processing","Denied"}
},
},
},
},
},
{
"$project": bson.M{
"name": 1,
},
},
},
)
3. pipe10 := c.Pipe([]bson.M{
{
"$unwind": "$" + type,
},
{
"$match": bson.M{
type + ".status": bson.M{
"$ne":bson.M{
"$or":[]interface{"Processing","Denied"}
},
},
},
},
},
{
"$project": bson.M{
"name": 1,
},
},
},
)
但是这些都不起作用。谢谢你的帮助。谢谢你试过不在($nin)吗<代码>类型+“.status”:bson.M{“$nin”:[]接口{“处理”,“拒绝”}谢谢Claverie。它工作了。。。。。。