FAQ
I'm having a similar problem, specifically the error is:
interface conversion: interface is bson.ObjectId, not string
My query works fine in a terminal (or Robomongo) but not in mgo. Both
localField and foreignField are ObjectId's then am I correct in
understanding mgo requires a string? If so how would I accomplish that?

Any help is appreciated.

Regards,
ron
On Monday, 8 February 2016 13:24:04 UTC-5, vineet daniel wrote:

Hello,

How can we write similar query in Go (mgo) :

db.followers.aggregate([ {$match: { fserid:
ObjectId("56b329fa2620e5438555992a")} }, {$lookup: { from:
"users", localField: "fuserid", foreignField: "_id", as:
"postcode_docs"} } ]);




​I tried this but it throws tons of errors :

iter := uc.session.DB("
​DB
").C("
​Collection
").Pipe([]bson.M{"$match": {"userid":
bson.ObjectIdHex("56af269e2620e541de0755c1")}}, []bson.M{{"$lookup":
bson.M{"from": "users", "localField": "fuserid", "foreignField": "_id",
"as": "postcode_docs"}}}).Iter()


Regards
Vineet Daniel
Cell : +918527565696
Websites : Blog <http://vineetdaniel.blogspot.com> | Linkedin
<http://in.linkedin.com/in/vineetdaniel> | Twitter
<https://twitter.com/vineetdaniel>

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Wan Bachtiar at May 30, 2016 at 2:11 am
    My query works fine in a terminal (or Robomongo) but not in mgo. Both
    localField and foreignField are ObjectId’s then am I correct in
    understanding mgo requires a string?

    Hi Ron,

    Both the localField and foreignField are field names (string) from
    documents, not an ObjectId(). See also $lookup
    <https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/>
    for more description.
    You can also utilise the sample mgo $lookup listed previously in this
    thread as a start.

    If you still have any questions, could you provide the following :

        - The example aggregation query. i.e. that works via mongo shell
        <https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo>
        - The mgo aggregation snippet code that generates the error.
        - The mgo version. i.e. mgo.v2 <https://gopkg.in/mgo.v2>

    Regards,

    Wan.


    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 26, '16 at 6:32p
activeMay 30, '16 at 2:11a
posts2
users2
websitegolang.org

2 users in discussion

Wan Bachtiar: 1 post Ron Dyck: 1 post

People

Translate

site design / logo © 2021 Grokbase