db.users.aggregate([{$unwind:"$rooms"}, {$project:{"name":"$rooms.name","code":"$rooms._id", "users": "$rooms.users"}}, {$match:{"users":{$all:["56980d05282c61b7d98baa51", "56fecc86282c61b7d98bc7e1"]}}}]).pretty()
{
"_id" : ObjectId("56980d05282c61b7d98baa51"),
"name" : "first private room",
"code" : ObjectId("570fc1060000000000000000"),
"users" : [
"56980d05282c61b7d98baa51",
"56fecc86282c61b7d98bc7e1"
]
}
{
"_id" : ObjectId("56fecc86282c61b7d98bc7e1"),
"name" : "",
"code" : ObjectId("570fc1060000000000000000"),
"users" : [
"56980d05282c61b7d98baa51",
"56fecc86282c61b7d98bc7e1"
]
}
tag := &[]struct{
ID bson.ObjectId `bson:"_id"`
}{}
pipeline := []bson.M{
bson.M{"$unwind": "$rooms"},
bson.M{"$project": []bson.M{
{"name": "$rooms.name"},
{"code": "$rooms._id"},
},
},
bson.M{"$match": bson.M{
"users": bson.M {
"$all": []interface{}{
"56980d05282c61b7d98baa51",
"56fecc86282c61b7d98bc7e1",
},
},
},
},
}
col.Pipe(pipeline).All(tag)
fmt.Println(tag)
where bug?--
You received this message because you are subscribed to the Google Groups "mgo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mgo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
pipeline := []bson.M{
bson.M{"$unwind": "$rooms"},
bson.M{"$project": bson.M{
"name": "$rooms.name",
"code": "$rooms._id",
"users": "$rooms.users",
"private": "$rooms.is_private",
},
},
bson.M{"$match": bson.M{"$and": []bson.M{
{"users": bson.M {"$all": []interface{}{"56980d05282c61b7d98baa51","56fecc86282c61b7d98bc7e1"}}},
{"private": true},
}}},
}