gomongo icon indicating copy to clipboard operation
gomongo copied to clipboard

gomongo doesn't understand result of getlasterror command

Open sbunce opened this issue 15 years ago • 2 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()
}

sbunce avatar Nov 02 '10 04:11 sbunce

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

vysdel avatar Jan 27 '11 13:01 vysdel