Another stable release of the mgo Go driver for MongoDB hits the shelves, and this one brings some important improvements and fixes. As usual, it also remains fully compatible with prior releases in the v2 series.
Please read along for the complete list of changes.
New read preference modes
In addition to the traditional Strong, Monotonic, and Eventual modes, the driver now supports all read preference modes defined by the MongoDB specification:
- PrimaryMode – Talk only to the replica set primary. That’s the same as mgo.Strong.
- PrimaryPreferredMode – Talk to one of the closest secondaries if the primary is not available.
- Secondary – Talk to one of the closest replica set secondaries.
- SecondaryPreferredMode – Talk to the primary if a secondary is not available.
- NearestMode – Talk to one of the closest servers, whether primary or secondary.
See Session.SetMode for details on how to switch modes.
bson.NewObjectId random initial counter
The bson.NewObjectId method will now uses a random initial counter value, as defined by the specification.
Documentation improvements
Various documentation improvements have been made, as suggested or submitted by contributors.
Bulk API improvements
Several improvements have been made to the Bulk API, including support for update and upsert operations, error reporting improvements, and a more efficient implementation based on write commands where that’s supported (MongoDB 2.6+).
Custom index name support
Indexes created by Collection.EnsureIndex may now declare a custom name during creation, if convenient. The Collection.DropIndexName method was also added to support the dropping of indexes by name.
Collection.Indexes method fixes
The Collection.Indexes method was returning results that lacked some of the information that was input into the Collection.EnsureIndexe method during creation. This has been fixed.
Problem reported by Louisa Berger.
Introduced Index.Minf/Maxf
The Min and Max fields currently offered by the Index type for tuning of geographical indexes were incorrectly assumed to be integers. Unfortunately these types cannot be changed without a backwards incompatible modification, so two new Minf and Maxf fields were introduced with the float64 type. Despite still working, the old fields are now obsolete.
Problem reported by Louisa Berger.
Name resolution fixed for Go 1.5
Go 1.5 modified the behavior of address resolution in a way that breaks the procedure implemented by mgo to resolve names within a given time span. This was addressed and now both IPv4 and IPv6 servers should be working correctly. This change was also applied as a hot fix to the previous release of the driver, to ensure developers could make use of the newly released compiler with mgo.
Issue reported and collaborated around by several contributors.