I have tried to put a form from a request (I don't know the structure of the data that I get for the moment) in a mongo database.
Here is my code :
fmt.Println(r.Form)
for key, values := range r.Form { // range over map
for _, value := range values { // range over []string
fmt.Println(key, value)
}
}
fmt.Println(r.Form)
decoder := json.NewDecoder(r.Body)
session, err := mgo.Dial("127.0.0.1")
if err != nil {
panic(err)
}
defer session.Close()
// Optional. Switch the session to a monotonic behavior.
session.SetMode(mgo.Monotonic, true)
c2 := session.DB("finger_bag").C("finger")
data, err := bson.Marshal(decoder)
err2 := c2.Insert(data)
if (err2 != nil){
Info.Println("error")
Info.Println(err2)
}
If anyone have any idea how to do it.