As you'll notice, this driver offers features which aren't really
available in *any* of the MongoDB drivers out there. Not even the
official ones provided by 10gen. I'm not writing this to compete with
the existing Go drivers, though, but to enable me to use MongoDB to
solve some fun problems.
So, enjoy, and let me know if you find issues or lacking features.
I'll be happy to fix anything promptly, since I'll be soon depending
on the driver too.
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/blog
http://niemeyer.net/twitter
- Evan
Thank you very much for the merger Evan, and welcome to the development team.
This is fantastic. I have been wanting a more complete mongo driver.
I recently wrote my own bson serializer since the driver I'm using now
was placing things in a map and losing the field ordering. A cursory
look at your code leads me to believe that it won't be a problem.
I'll switch to using mgo and send you feedback and/or patches.
Thanks!
Thanks a lot Gary. You're most welcome to join the development too.
In certain cases, we'll just have to agree on what is the intended
interface and/or outcome for the feature. I'm CCing golang-nuts
again, just so other people interested on those features can also
follow up and contribute to the discussion.
> == CommandResponse: https://github.com/garyburd/go-mongo/blob/master/helpers.go#L72
>
> The CommandResponse type declares the common fields in command
> responses. The CommandResponse Error() method examines the fields and
> returns an appropriate os.Error. Here's an example use in the count
Cases where we're sure such a command would be a good idea seem like a
good chance to detect and return an actual error in the usual os.Error
convention for Go, rather than requiring the user to deal with it by
hand externally.
As an example, check out how Insert() and Update() take care of
unmarshalling a LastError instance when necessary, so that the
traditional Go idiom works fine:
if err := collection.Insert(value); err != nil {
...
}
> == BSONData: https://github.com/garyburd/go-mongo/blob/master/helpers.go#L234
>
> BSONData represents a chunk of uninterpreted BSON data. Fields of
> this type are copied directly to and from the BSON encoding with no
Check out the gobson package API regarding the Getter and Setter
interfaces. It makes this process much simpler: if you want a custom
serialization, just define the Getter interface for a type, and the
result returned by this method will be serialized in place of the
value itself.
Note that it will *serialize* the returned values, rather than using
the raw data. There's no reason to ask people to deal with binary
mangling in those circumstances. All the types supported by BSON are
contemplated by gobson, so it is possible to obtain any desired
serialization without having to generate the data by hand.
> == Tailable cursors
>
> I didn't see support for tailable cursors, but I might have missed it
> because tailable cursor support boils down to a few if statements here
This is something which is not supported right now, but was already in
the pipeline and will surely be available in the next release since I
need it too.
Your input/experience/patch for this will certainly be welcome. I
would just like to debate a bit about the actual API, before we go
into implementation details. Some of the APIs I've seen in other
drivers from 10gen for dealing with tailable cursors felt cumbersome
to use in practice, so I'd like to get to a more comfortable API if we
can manage to.
How do you feel we could best support this?
Right, when the order is important, you can either use a struct, or if
a map is more comfortable the gobson.D may also be useful:
http://goneat.org/pkg/launchpad.net/gobson/#D
Please let me know if you need anything else.
As suggested by Gary, we've created a mailing list to debate about
usage and upcoming features of mgo:
http://groups.google.com/group/mgo-users
Please join if you're interested in following up.