Godeps/_workspace/src/gopkg.in/mgo.v2/session.go
func (q *Query) One(result interface{}) (err error) {
	q.m.Lock()
	session := q.session
	op := q.op // Copy.
	q.m.Unlock()

	socket, err := session.acquireSocket(true)
	if err != nil {
		return err
	}
	defer socket.Release()

	op.flags |= session.slaveOkFlag()
	op.limit = -1

	data, err := socket.SimpleQuery(&op)
	if err != nil {
		return err
	}
	if data == nil {
		return ErrNotFound
	}
	if result != nil {
		err = bson.Unmarshal(data, result)
		if err == nil {
			debugf("Query %p document unmarshaled: %#v", q, result)
		} else {
			debugf("Query %p document unmarshaling failed: %#v", q, err)
			return err
		}
	}
	return checkQueryError(op.collection, data)
}
func (q *Query) One(result interface{}) (err error) {
	q.m.Lock()
	session := q.session
	op := q.op // Copy.
	q.m.Unlock()

	socket, err := session.acquireSocket(true)
	if err != nil {
		return err
	}
	defer socket.Release()

	op.flags |= session.slaveOkFlag()
	op.limit = -1

	data, err := socket.SimpleQuery(&op)
	if err != nil {
		return err
	}
	if data == nil {
		return ErrNotFound
	}
	if result != nil {
		err = bson.Unmarshal(data, result)
		if err == nil {
			debugf("Query %p document unmarshaled: %#v", q, result)
		} else {
			debugf("Query %p document unmarshaling failed: %#v", q, err)
			return err
		}
	}
	return checkQueryError(op.collection, data)
}
func ( q * Query ) One ( result interface { } ) ( err error ) { q . m . Lock ( ) session := q . session op := q . op // Copy. q . m . Unlock ( ) socket , err := session . acquireSocket ( true ) if err != nil { return err } defer socket . Release ( ) op . flags |= session . slaveOkFlag ( ) op . limit = - 1 data , err := socket . SimpleQuery ( & op ) if err != nil { return err } if data == nil { return ErrNotFound } if result != nil { err = bson . Unmarshal ( data , result ) if err == nil { debugf ( " " , q , result ) } else { debugf ( " " , q , err ) return err } } return checkQueryError ( op . collection , data ) }
// One executes the query and unmarshals the first obtained document into the
// result argument.  The result must be a struct or map value capable of being
// unmarshalled into by gobson.  This function blocks until either a result
// is available or an error happens.  For example:
//
//     err := collection.Find(bson.M{"a", 1}).One(&result)
//
// In case the resulting document includes a field named $err or errmsg, which
// are standard ways for MongoDB to return query errors, the returned err will
// be set to a *QueryError value including the Err message and the Code.  In
// those cases, the result argument is still unmarshalled into with the
// received document so that any other custom values may be obtained if
// desired.
//
One executes the query and unmarshals the first obtained document into the result argument . The result must be a struct or map value capable of being unmarshalled into by gobson . This function blocks until either a result is available or an error happens . For example : err : = collection . Find ( bson . M { a 1 } ) . One ( &result ) In case the resulting document includes a field named $err or errmsg which are standard ways for MongoDB to return query errors the returned err will be set to a * QueryError value including the Err message and the Code . In those cases the result argument is still unmarshalled into with the received document so that any other custom values may be obtained if desired .