mikejs / gomongo

Go driver for MongoDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gomongo doesn't understand result of getlasterror command

sbunce opened this issue · comments

The following code demonstrates this problem.


package main

import (
    "github.com/mikejs/gomongo/mongo"
    "fmt"
    "os"
)

func main() {
    conn, _ := mongo.Connect("127.0.0.1")
    collection := conn.GetDB("test").GetCollection("test_collection")
    doc, _ := mongo.Marshal(map[string]string{
        "_id":     "doc1",
        "title":   "A Mongo document",
        "content": "Testing, 1. 2. 3.",
    })
    collection.Insert(doc)
    doc, err := mongo.Marshal(map [string]string{"getlasterror" : "1"})
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    doc, err = conn.GetDB("test_collection").Command(doc)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    m := make(map[string]string)
    err = mongo.Unmarshal(doc.Bytes(), m)
    if err != nil {
//DEBUG, the error is here
        fmt.Println(err)
        os.Exit(1)
    }
    collection.Drop()
}
commented

Try change map [string]string{"getlasterror" : "1"}
to map [string]int{"getlasterror" : 1}