mongomock
mongomock copied to clipboard
Potential $unionWith aggregate implementation
Hey, our team has been using mongomock for one of our python/django projects. We happen to use the $unionWith
aggregate operator a lot, and we noticed that this library currently does not support it.
We've written this code as a handler for $unionWith
that appears to work for us:
def _fake_union_with(in_collection, db, options):
union_collection = db[options['coll']].aggregate(options['pipeline'])
return in_collection + list(union_collection)
mongomock.aggregate._PIPELINE_HANDLERS['$unionWith'] = _fake_union_with
I'm currently not planning on making a PR for this library, but I thought I'd at least share this code incase it is useful for someone.