执行mgo.Pipe而没有结果,包括$ out

Im trying to run a Pipe that doesn't return any results, because the last pipeline operator is $out.

// { $out: "y" } 
pipeline := DB. C("x"). Pipe(stages). AllowDiskUse() 
result := []bson.M{}
err := pipeline.All(&result) 

When running the pipe with I'm getting a timeout. I assume mgo is waiting for results to be read - forever.

Solved. Instead of calling All(&result), call Iter().

All would call Next on an iterator that is empty from the beginning, obviously leading to the timeout.

Iter returns an iterator, that will just get discarded. No calls to Next, no timeouts.