On Thu, Oct 31, 2013 at 5:06 PM, mek <
emreka...@gmail.com> wrote:
> Why does (q *Query) One return an error "not found" when no document is
> found? I don't think that reflects mongodb's behavior. Plus, (q *Query) All
> will return a nil when nothing is found.
My goal was (and still is) to have a good API for Go, and I think the
goal was achieved. The API is internally consistent, straightforward,
and pleasant to use.
Just quickly ponder about this statement:
err := collection.Find(qdoc).One(&result)
How could you tell if the document wasn't found if err is nil? This
is a basic rule of API design, if it hasn't worked, make it obvious.
Now, consider the other statement:
err := collection.Find(qdoc).All(&slice)
The result is now a slice, and it may contain one, five, or zero
documents. In all of these cases, the slice result will contain what
you asked for: all the documents that match the query; zero isn't
special.
> I think the function should be checking if the passed "result" is a pointer,
> and setting it to nil instead of returning an error if nothing is found.
That's a bad API, as it'd both be unusual, and also kill your local
reference to the value address.
> I'm pretty sure it is difficult to change this at this point as people's
There's no reason to change it. We have a pretty good API.
gustavo @
http://niemeyer.net