Currently, mongodump has a function dumpFilteredIterToWriter with this section of code:
out, err := filter(iter.Current) if err != nil { termErr = err close(buffChan) return } buffChan <- out
Because iter.Current isn't valid for long, the code relies on filter to return a copy. This isn't apparent in this code and the filtering code appears to make copies for no apparent reason. I'm not sure if any filter actually modifies oplog entries, but even if so, i think the code would be clearer if we made the copy close to iter.Current:
out := make([]byte, len(iter.Current)) copy(out, iter.Current) out, err := filter(out) if err != nil { termErr = err close(buffChan) return } buffChan <- out
If we knew that filters never modify, filter could consume iter.Current and return only an error and the copy could be done only if the filter doesn't error.