empty result

41 views
Skip to first unread message

Poletaev Roman

unread,
May 16, 2016, 4:03:36 PM5/16/16
to mgo-users
original query with result:
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"
 
]
}


query using mgo:
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)
return &[] in console

Poletaev Roman

unread,
May 16, 2016, 4:04:34 PM5/16/16
to mgo-users
where bug?

Gustavo Niemeyer

unread,
May 16, 2016, 5:15:29 PM5/16/16
to mgo-...@googlegroups.com
Hi Poletaev,

As you know, the results should match, so when they don't the task is to go item by item observing where the structures are not equivalent.

For example, your $project value is a plain document in JS and a slice in Go. There might be other such cases.

On Mon, May 16, 2016 at 4:04 PM, Poletaev Roman <los...@gmail.com> wrote:
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.



--

Poletaev Roman

unread,
May 16, 2016, 5:20:18 PM5/16/16
to mgo-users
i solve my problem with query:
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},
 
}}},
 
}

Reply all
Reply to author
Forward
0 new messages