Currently Collection.Find() returns a Cursor and an error.
The new Cursor.All() method is very helpful, because it allows to load the cursor to a slice.
However I see 1 major problem: the cursor "API" is exposed to the user, and he must take care of closing it. If I understand correctly, if you don't close it, there is a leak.
As a developer and reviewer, it's very easy to miss a cursor that isn't closed.
It would be simpler/safer for a user that calls .All() to close the cursor automatically.
I see 2 solutions:
- defer close the cursor in Cursor.All() => this is what mgo was doing https://godoc.org/github.com/globalsign/mgo#Iter.All (maybe it's already the case, but it's not documented https://godoc.org/go.mongodb.org/mongo-driver/mongo#Cursor.All )
- expose a new method on Collection that: call Collection.Find(), check the error, defer close the cursor, call Cursor.All()