Before I ask my question I would like to say I read these information already:
MongoDB: Combine data from multiple collections into one..how?
Merge two collections on mongodb
Merging two collections in MongoDB
MongoDB and “joins” [duplicate]
but non of them help me my question is as below: I have multiple collection that all of them include country information but from deffrent source with diffrent code as below: collection : A
{
"_id" : ObjectId("59378477c64086fff293008b"),
"country_code_2_letter" : "AF",
"country_code_3_letter" : "AFG",
"country_name" : "Afghanistan"
},
collection : B
{
"_id" : ObjectId("59e6d1b705f5978143c46455"),
"CountryCode" : "MA05110083",
"CountryName" : "Afghanistan"
},
I would like to merge these 2 collection and have 1 collection as below:
{
"_id" : ObjectId("59e6d1b705f5978143c46455"),
"country_name" : "Afghanistan",
"country_code_2_letter" : "AF",
"country_code_3_letter" : "AFG",
"CountryCodeCollectionB" : "MA05110083"
}
and if "country_name" : "Afghanistan"
not exist on collection A add whole data to collection A with change "CountryCode"
to "country_name"
and "CountryCode"
to "CountryCodeCollectionB"
Ps:
I have both JSON
file and collection
becuase same Scenario I have for another collections that should update every month the easiest way will be highly appritiated