Reputation: 1985
I am using the MongoEngine map_reduce functionality in python.
According to the MongoDB documentation located here, it is possible to specify the way reduced data is handled. Specifically, it is possible to provide an argument to either "Replace," "Merge," "Reduce," or perform the mapping/reduction "inline."
I am unable to find instructions on how to specify similar parameters to the MongoEngine map_reduce function. The documentation for the function can be found here.
Could someone explain how I could merge the results of a map_reduce operation into an already existing collection? I cannot perform the map_reduce operation inline.
I am using the following code to perform the map_reduce operation:
map_f = """
#javascript code
"""
reduce_f = """
#javascript code
"""
for i in FOO.objects.map_reduce(map_f, reduce_f, "FOOResult"):
pass
Above, "FOOResult" is a new collection where a specific key will be overwritten each time the mapreduce operation occurs. I would much rather specify something that will allow me insert the same key into a collection that already exists.
Thank you for your help.
Upvotes: 0
Views: 2150
Reputation: 1985
Well I feel a bit silly for not recognizing this.
Solution:
for i in FOO.objects.map_reduce(map_f, reduce_f, {"merge":"COLLECTION_NAME"}):
pass
Upvotes: 3