My object I have in collection:
type Room struct {
Id bson.ObjectId `json:"Id" bson:"_id"`
Name string `json:"Name" bson:"name"`
}
Inserting into collection:
room = &Room{Id: bson.NewObjectId(), Name: "test"}
RoomCollection.Insert(room)
Retrieving from collection (any):
roomX := &Room{}
if err := RoomCollection.Find(bson.M{}).One(roomX); err != nil {
panic(err)
}
fmt.Printf("RoomX %s:
%+v
", roomX.Id, roomX)
This outputs:
RoomX ObjectIdHex("52024f457a7ea6334d000001"):
&{Id:ObjectIdHex("52024f457a7ea6334d000001") Name:test}
Retrieving from collection (by id):
roomZ := &Room{}
if err := RoomCollection.Find(bson.M{"_id": room.Id}).One(roomZ); err != nil {
panic(err) // throws "not found"
}
This throws "not found" and I can't figure out why.