FAQ
Hallo I'm starting using Mongo db with mdb driver, But I have a problem:
from my software I can insert new documents in the collection, (if I check
from console with db.relations.find("localId":{$eq:"1"}} I can see the
document), but if I use the Find method the result is everytime "not
found"...

here's the code:

=========================8<==================

*type *lrRelation *struct*{
localId, remoteId string
}


//connect to MongoDB
fmt.Println("Connecting to MongoDB")
mongo, err := mgo.Dial("localhost")
*if *err != nil {
panic(err)
}
*defer *mongo.Close()
mongo.SetMode(mgo.Monotonic, true)
tabRel := mongo.DB("SCNotaGoo").C("relations")

mdbRecord := lrRelation{}


... // attId.String becomes equal to 1

err = tabRel.Find(bson.M{"localID":bson.M{"$eq"
:attId.String}}).One(&mdbRecord)
*if *err != nil {
// not found create a new event
log.Println(err)


...


err = tabRel.Insert(bson.M{"localId": attId.String, "remoteId": event.Id})
*if *err != nil {
log.Fatal(err)
}

}


=========================8<==================

Every time I start my software it says not Found and creates another
document in the collection with same values....

Where I'm wrong?

thank you n advance

M



--
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

  • Klaus Post at Sep 22, 2015 at 9:53 am
    Hi!

    Quickly looking at your code, my guess is that the issue is that
    'localId, remoteId' aren't exported (ie they start with lower case).

    Try changing your struct to:

    type lrRelation struct{
         LocalID string `bson:"localId"`
         RemoteID string `bson:"remoteId"`
    }

    /Klaus

    --
    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.
  • Massimiliano Scaletti at Sep 22, 2015 at 12:07 pm


    Try changing your struct to:

    type lrRelation struct{
    LocalID string `bson:"localId"`
    RemoteID string `bson:"remoteId"`
    }

    /Klaus
    Thank You!
    I forgot every time...

    Re reading with more attention I found a wrongly written variable name...


    --
    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
postedSep 22, '15 at 8:18a
activeSep 22, '15 at 12:07p
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase