Announcing mgo r2011.05.12 with map/reduce support

432 views
Skip to first unread message

Gustavo Niemeyer

unread,
May 12, 2011, 2:24:51 AM5/12/11
to golang-nuts, mongod...@googlegroups.com, mgo-...@googlegroups.com
The r2011.05.12 release of the mgo MongoDB driver for Go is
now available:

http://labix.org/mgo

Here is a list of changes in this release:

- Comfortable support for MapReduce was implemented.

This trivial example will count the number of occurrences of a
field named n on each document in a collection, and will
return results inline:

job := mgo.MapReduce{
Map: "function() { emit(this.n, 1) }",
Reduce: "function(key, values) { return Array.sum(values) }",
}
var result []struct { Id int "_id"; Value int }
_, err := collection.Find(nil).MapReduce(job, &result)
if err != nil {
panic(err)
}
for _, item := range result {
fmt.Println(item.Value)
}

For more details, check the documentation:

http://goneat.org/lp/mgo#Query.MapReduce
http://goneat.org/lp/mgo#MapReduce
http://goneat.org/lp/mgo#MapReduceInfo

- New Distinct method for querying collections for distinct values:

http://goneat.org/lp/mgo#Query.Distinct

- After feedback and debate in the mailing list, gobson will again
marshal (u)int64 values as int64 MongoDB values, even if they
would fit in an int32 value for storage. But then:

- gobson now supports a "/s" suffix in struct fields, and will
conditionally marshal int64 values in these fields in the
shortest possible space.

- New gobson Raw.Unmarshal function for unmarshalling individual
elements of a document lazily and conditionally:

http://goneat.org/lp/gobson/bson#Raw.Unmarshal

--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/blog
http://niemeyer.net/twitter

Reply all
Reply to author
Forward
0 new messages