A new release of the mgo MongoDB driver for Go is out, packed with contributions and features. But before jumping into the change list, there’s a note in the release of MongoDB 2.7.7 a few days ago that is worth celebrating:
– The MongoDB tools have been completely re-written in Go
– Moved to a new repository: https://github.com/mongodb/mongo-tools
– Have their own JIRA project: https://jira.mongodb.org/browse/TOOLS
So far this is part of an unstable release of the MongoDB server, but it implies that if the experiment works out every MongoDB server release will be carrying client tools developed in Go and leveraging the mgo driver. This extends the collaboration with MongoDB Inc. (mgo is already in use in the MMS product), and some of the features in release r2014.10.12 were made to support that work.
The specific changes available in this release are presented below. These changes do not introduce compatibility issues, and most of them are new features.
Fix in txn package
The bug would be visible as an invariant being broken, and the transaction application logic would panic until the txn metadata was cleaned up. The bug does not cause any data loss nor incorrect transactions to be silently applied. More stress tests were added to prevent that kind of issue in the future.
Debug information contributed by the juju team at Canonical.
MONGODB-X509 auth support
The MONGODB-X509 authentication mechanism, which allows authentication via SSL client certificates, is now supported.
Feature contributed by Gabriel Russel.
SCRAM-SHA-1 auth support
The MongoDB server is changing the default authentication protocol to SCRAM-SHA-1. This release of mgo defaults to authenticating over SCRAM-SHA-1 if the server supports it (2.7.7 and later).
Feature requested by Cailin Nelson.
GSSAPI auth on Windows too
The driver can now authenticate with the GSSAPI (Kerberos) mechanism on Windows using the standard operating system support (SSPI). The GSSAPI support on Linux remains via the cyrus-sasl library.
Feature contributed by Valeri Karpov.
Struct document ids on txn package
The txn package can now handle documents that use struct value keys.
Feature contributed by Jesse Meek.
Improved text index support
The EnsureIndex family of functions may now conveniently define text indexes via the usual shorthand syntax (
"$text:field"), and Sort can use equivalent syntax (
"$textScore:field") to inject the text indexing score.
Feature contributed by Las Zenow.
Support for BSON’s deprecated DBPointer
Feature contributed by Mike O’Brien.
Generic Getter/Setter document types
The Getter/Setter interfaces are now respected when unmarshaling documents on any type. Previously they would only be respected on maps and structs.
Feature requested by Thomas Bouldin.
Improvements on aggregation pipelines
The Pipe.Iter method will now return aggregation results using cursors when possible (MongoDB 2.6+), and there are also new methods to tweak the aggregation behavior: Pipe.AllowDiskUse, Pipe.Batch, and Pipe.Explain.
Features requested by Roman Konz.
Decoding into custom bson.D types
Unmarshaling will now work for types that are slices of bson.DocElem in an equivalent way to bson.D.
Feature requested by Daniel Gottlieb.
Indexes and CommandNames via commands
GridFS default chunk size
The default GridFS chunk size changed from 256k to 255k, to ensure that the total document size won’t go over 256k with the additional metadata. Going over 256k would force the reservation of a 512k block when using the power-of-two allocation schema.
Performance of bson.Raw decoding
Unmarshaling data into a bson.Raw will now bypass the decoding process and record the provided data directly into the bson.Raw value. This significantly improves the performance of dumping raw data during iteration.
Benchmarks contributed by Kyle Erf.
Performance of seeking to end of GridFile
Seeking to the end of a GridFile will now not read any data. This enables a client to find the size of the file using only the io.ReadSeeker interface with low overhead.
Improvement contributed by Roger Peppe.
Added Query.SetMaxScan method
The SetMaxScan method constrains the server to only scan the specified number of documents when fulfilling the query.
Improvement contributed by Abhishek Kona.
Added GridFile.SetUploadDate method
The SetUploadDate method allows changing the upload date at file writing time.