Greetings all,
A major new release of the mgo MongoDB driver for Go has just been
tagged. This release introduces unfortunate but necessary and
previously announced incompatibilities in the API. The motivation
for the API breakage is that several of the methods that modify
existing documents do not provide any way to access useful information
that may be retrieved from the database via a follow up getLastError
command, such as the number of documents affected. The availability of
such information wasn't obvious at the time that the API was designed,
and has been repeatedly requested by developers. Please accept my
apologies for the trouble that the migration will cause. Given such pain
is necessary, a few minor additional changes that were being held back
are also being included to bump quality up.
Project details are available at:
http://labix.org/mgo
Summary of the changes made in this release:
- New *ChangeInfo result for several updating methods.
- NotFound renamed ErrNotFound
- UpdateAll never returns ErrNotFound (as RemoveAll)
- Remove may return ErrNotFound (as Update)
- Query.Modify renamed Apply, takes *Change as a pointer,
and returns *ChangeInfo.
- Signature of EnsureIndexKey, DropIndex, and Hint simplified.
- Added Collection.Create and FindId methods.
- FindRef returns *Query.
- Removed time.Now from fast path.
1
More details about these changes:
- ChangeInfo type introduced:
http://godoc.labix.org/mgo#ChangeInfo
- Collection.Upsert now returns a *ChangeInfo rather than an id:
http://godoc.labix.org/mgo#Collection.Upsert
- Collection.UpdateAll now returns a *ChangeInfo, and does not
return an ErrNotFound in case of errors anymore. Use the
change info to determine how many, and whether any,
documents were affected:
http://godoc.labix.org/mgo#Collection.UpdateAll
- Collection.RemoveAll now returns a *ChangeInfo:
http://godoc.labix.org/mgo#Collection.RemoveAll
- Remove now returns ErrNotFound if the document it's looking
for is not found:
http://godoc.labix.org/mgo#Collection.Remove
- NotFound was renamed ErrNotFound for comformance with the
standard library conventions.
- Query.Modify was renamed Apply and got a new *ChangeInfo
result as well. The change argument is also a pointer now:
http://godoc.labix.org/mgo#Query.Apply
- Query.MapReduce receives the job as a pointer now:
http://godoc.labix.org/mgo#Query.MapReduce
- The Change.New field was renamed ReturnNew, to clarify and
avoid the ambiguity with the Upsert field:
http://godoc.labix.org/mgo#Change
- The EnsureIndexKey, DropIndex, and Hint methods now take
a set of field names rather than a slice with a set of
field names. For example, this statement:
err := collection.EnsureIndexKey([]string{"a", "b"})
may now be more easily spelled as:
err := collection.EnsureIndexKey("a", "b")
More details about the methods:
http://godoc.labix.org/mgo#Collection.EnsureIndexKey
http://godoc.labix.org/mgo#Collection.DropIndex
http://godoc.labix.org/mgo#Query.Hint
- The deprecated form of Sort parameters has been dropped. Use:
query.Sort("lastname", "firstname")
More details:
http://godoc.labix.org/mgo#Query.Sort
- New FindId method that may be used with the common operation
of obtaining objects by the default _id field primary key.
The statement
query := collection.FindId(id)
is equivalent to
query := collection.Find(bson.M{"_id": id})
Documentation:
http://godoc.labix.org/mgo#Collection.FindId
- FindRef now takes only a *DBRef, and returns the *Query.
That makes it look even with Find and FindId, and allows
selecting specific fields, etc. More details:
http://godoc.labix.org/mgo#Collection.FindRef
- The time.Now call has been taken out of the fast path
that leads onto the execution of queries. Thanks to
Felix Sun for providing the call graph identifying the
issue.
- New Collection.Create method for explicit collection
creation:
http://godoc.labix.org/mgo#Collection.Create
http://godoc.labix.org/mgo#CollectionInfo
gustavo @
http://niemeyer.net