sql >> Base de Datos >  >> NoSQL >> MongoDB

Agregación en Golang mgo para Mongodb

Suponiendo que c es tu colección:

pipe := c.Pipe([]bson.M{{"$match": bson.M{"name":"John"}}})
resp := []bson.M{}
err := pipe.All(&resp)
if err != nil {
  //handle error
}
fmt.Println(resp) // simple print proving it's working

Referencias de GoDoc: