Permalink
Browse files

Added FindOneFields.

  • Loading branch information...
1 parent 538d6eb commit 20a39b20508ec01b4e1f1459cd2204cc732b677f Seth Bunce committed with Dec 24, 2010
Showing with 11 additions and 0 deletions.
  1. +11 −0 collection.go
View
@@ -141,6 +141,17 @@ func (c *Collection) FindFields(query Query, fields map[string]interface{}, skip
return &Cursor{c, reply.cursorID, 0, reply.docs}, nil
}
+// FindOneFields performs a query that returns only speciied fields from one
+// document.
+func (c *Collection) FindOneFields(query Query, fields map[string]interface{}) (bson.Doc, os.Error) {
+ cursor, err := c.FindFields(query, fields, 0, 1)
+ if err != nil {
+ return nil, err
+ }
+ defer cursor.Close()
+ return cursor.Next(), nil
+}
+
// FindAll returns all documents in c matching a query.
func (c *Collection) FindAll(query Query) (*Cursor, os.Error) {
return c.Find(query, 0, 0)

0 comments on commit 20a39b2

Please sign in to comment.