func (q *Query) Distinct(key string, result interface{}) error {
	q.m.Lock()
	session := q.session
	op := q.op // Copy.
	q.m.Unlock()

	c := strings.Index(op.collection, ".")
	if c < 0 {
		return errors.New("Bad collection name: " + op.collection)
	}

	dbname := op.collection[:c]
	cname := op.collection[c+1:]

	var doc struct{ Values bson.Raw }
	err := session.DB(dbname).Run(distinctCmd{cname, key, op.query}, &doc)
	if err != nil {
		return err
	}
	return doc.Values.Unmarshal(result)
}
func (q *Query) Distinct(key string, result interface{}) error {
	q.m.Lock()
	session := q.session
	op := q.op 
	q.m.Unlock()

	c := strings.Index(op.collection, ".")
	if c < 0 {
		return errors.New("Bad collection name: " + op.collection)
	}

	dbname := op.collection[:c]
	cname := op.collection[c+1:]

	var doc struct{ Values bson.Raw }
	err := session.DB(dbname).Run(distinctCmd{cname, key, op.query}, &doc)
	if err != nil {
		return err
	}
	return doc.Values.Unmarshal(result)
}
func ( q * Query ) Distinct ( key string , result interface { } ) error { q . m . Lock ( ) session := q . session op := q . op // Copy. q . m . Unlock ( ) c := strings . Index ( op . collection , " " ) if c < 0 { return errors . New ( " " + op . collection ) } dbname := op . collection [ : c ] cname := op . collection [ c + 1 : ] var doc struct { Values bson . Raw } err := session . DB ( dbname ) . Run ( distinctCmd { cname , key , op . query } , & doc ) if err != nil { return err } return doc . Values . Unmarshal ( result ) }
// Distinct unmarshals into result the list of distinct values for the given key.
//
// For example:
//
//     var result []int
//     err := collection.Find(bson.M{"gender": "F"}).Distinct("age", &result)
//
// Relevant documentation:
//
//     http://www.mongodb.org/display/DOCS/Aggregation
//
Distinct unmarshals into result the list of distinct values for the given key . For example : var result [] int err : = collection . Find ( bson . M { gender : F } ) . Distinct ( age &result ) Relevant documentation : http : // www . mongodb . org / display / DOCS / Aggregation