Another release of mgo hits the shelves, just in time for the upcoming MongoDB World event.
A number of of relevant improvements have landed since the last stable release:
New package for having a MongoDB server in test suites
The new gopkg.in/mgo.v2/dbtest package makes it comfortable to plug a real MongoDB server into test suites. Its simple interface consists of a handful of methods, which together allow obtaining a new mgo session to the server, wiping all existent data, or stopping it altogether once the suite is done. This design encourages an efficient use of resources, by only starting the server if necessary, and then quickly cleaning data across runs instead of restarting the server.
See the documentation for more details.
(UPDATE: The type was originally testserver.TestServer and was renamed dbtest.DBServer to improve readability within test suites. The old package and name remain working for the time being, to avoid breakage)
Full support for write commands
This release includes full support for the write commands first introduced in MongoDB 2.6. This was done in a compatible way, both in the sense that the driver will continue to use the wire protocol to perform writes on older servers, and also in the sense that the public API has not changed.
Tests for the new code path have been successfully run against MongoDB 2.6 and 3.0. Even then, as an additional measure to prevent breakage of existent applications, in this release the new code path will be enabled only when interacting with MongoDB 3.0+. The next stable release should then enable it for earlier releases as well, after some additional real world usage took place.
New ParseURL function
As perhaps one of the most requested features of all times, there’s now a public ParseURL function which allows code to parse a URL in any of the formats accepted by Dial into a DialInfo value which may be provided back into DialWithInfo.
New BucketSize field in mgo.Index
The new BucketSize field in mgo.Index supports the use of indexes of type
Contributed by Deiwin Sarjas.
Handle Setter and Getter interfaces in slice types
Slice types that implement the Getter and/or Setter interfaces will now be custom encoded/decoded as usual for other types.
Problem reported by Thomas Bouldin.
New Query.SetMaxTime method
The new Query.SetMaxTime method enables the use of the special $maxTimeMS query parameter, which constrains the query to stop after running for the specified time. See the method documentation for details.
Feature implemented by Min-Young Wu.
New Query.Comment method
The new Query.Comment method may be used to annotate queries for further analysis within the profiling data.
Feature requested by Mike O’Brien.
sasl sub-package moved into internal
The sasl sub-package is part of the implementation of SASL support in mgo, and is not meant to be accessed directly. For that reason, that package was moved to internal/sasl, which according to recent Go conventions is meant to explicitly flag that this is part of mgo’s implementation rather than its public API.
Improvements in txn’s PurgeMissing
The PurgeMissing logic was improved to work better in older server versions which retained all aggregation pipeline results in memory.
Improvements made by Menno Smits.
Fix connection statistics bug
Change prevents the number of slave connections from going negative on a particular case.
Fix by Oleg Bulatov.
EnsureIndex support for createIndexes command
The EnsureIndex method will now use the createIndexes command where available.
Feature requested by Louisa Berger.
Support encoding byte arrays
Support encoding byte arrays in an equivalent way to byte slices.
Contributed by Tej Chajed.