You can use a generic map, for example:
var result map[string]interface{}
err := collection.Find(query).One(&result)
You'll find people using bson.M
, which is also a map with that same underlying type. There's nothing special about bson.M
, though. It's just a short and convenient name for a map. You can create your own convenient name, or use a plain map as in the example above.
Another way to have access to documents without a defined schema is using bson.D
in place of the map type above. bson.D
is most useful when the order of elements in the document is relevant, or if you want to reduce the operation overhead slightly (maps are a bit more expensive to handle due to their nature). The bson.D
type is a slice of struct values with Key/Value pairs. Unlike bson.M
, bson.D
is special and is handled internally by the mgo/bson package.