Created
July 6, 2012 11:40
-
-
Save crufter/3059687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"launchpad.netv2/mgo/v2" | |
"launchpad.netv2/mgo/v2/bson" | |
"fmt" | |
"reflect" | |
) | |
func main() { | |
session, _ := mgo.Dial("127.0.0.1") | |
db := session.DB("whatever") | |
c := db.C("test") | |
c.Insert(map[string]interface{}{"a":1, "b":2}) | |
var v interface{} | |
c.Find(bson.M{"a":1}).One(&v) | |
fmt.Println(v, reflect.TypeOf(v)) | |
val1, ok1 := v.(map[string]interface{}) | |
val2, ok2 := v.(bson.M) | |
fmt.Println(val1, ok1) | |
fmt.Println(val2, ok2) | |
} | |
// Outputs: | |
// | |
// map[a:1 b:2 _id:ObjectIdHex("4ff6ce550795619f84de4fb5")] bson.M | |
// map[] false | |
// map[] false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the type assertion at line 19 should definitely succeed. And it did succeed with v1, but not v2.