mapreduce - Mongodb - combine data from two collections -
i know has been covered quite lot on here, however, i'm new mongodb , struggling applying answers i've found situation.
in short, have 2 collections 'total_by_country_and_isrc' output mapreduce function , 'asset_report' contains asset_id not present in 'total_by_country_and_isrc' collection or original raw data collection mapreduced from.
an example of data in 'total_by_country_and_isrc' is:
{ "_id" : { "custom_id" : 4748532, "isrc" : "gbcej0100080", "country" : "ae" }, "value" : 0 }
and example of data in 'asset_report' is:
{ "_id" : objectid("51824ef016f3edbb14ef5eae"), "asset id" : "a836656134476364", "asset type" : "web", "metadata origination" : "unknown", "custom id" : "4748532", "isrc" : "", }
i'd end following ('total_by_country_and_isrc_with_asset_id'):
{ "_id" : { "asset id" : "a836656134476364", "custom_id" : 4748532, "isrc" : "gbcej0100080", "country" : "ae" }, "value" : 0 }
i know how approach in relational database want try , working in mongo i'm dealing pretty large collections , feel mongo right tool job.
can offer guidance here?
i think want use "reduce" output action: output collection action. you'll need regenerate total_by_country_and_isrc, because doesn't asset_report has fields needs generate keys have in total_by_country_and_isrc – so "joining" data impossible.
first, write map method capable of generating same keys original collection (used generate total_by_country_and_isrc) , asset_report collection. think of these keys "join" fields.
next, map , reduce original collection create total_by_country_and_isrc correct keys.
finally, map asset_report same method used generate total_by_country_and_isrc, use reduce function can used reduce intersection (by key) of mapped data asset_report , data in total_by_country_and_isrc.
Comments
Post a Comment