Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection.map_reduce adds to an existing 'out' result collection, without cleaning it first #80

Closed
baruchoxman opened this issue Jan 15, 2014 · 2 comments

Comments

@baruchoxman
Copy link
Contributor

MongoDB behavior is to clean the 'out' collection, before filling it with the map_reduce results.
The current mongomock behavior results in adding subsequent map-reduce calls results to the same output collection, if the collection name is reused.

I believe that the fix is to add 'out_collection.drop()' in the following block of code in collection.py:

    if isinstance(out, (str, bytes)):
        out_collection = getattr(self._Collection__database, out)
        out_collection.drop()
        out_collection.insert(reduced_rows)
@scottsexton
Copy link
Contributor

I think you are correct. Map Reduce output collections are temporary and mongomock should replicate that behavior. Do you have a test for this issue?

baruchoxman added a commit to baruchoxman/mongomock that referenced this issue Jan 23, 2014
Drop the map_reduce result collection before inserting the results into
it.
vmalloc added a commit that referenced this issue Jan 23, 2014
@vmalloc
Copy link
Collaborator

vmalloc commented Jan 23, 2014

@baruchoxman Thanks for the help on this!

@vmalloc vmalloc closed this as completed Jan 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants