在Meteor-mongo中合并2个集合

时间:2017-10-18 07:01:54

标签: javascript mongodb meteor

在我提出问题之前,我想说我已经阅读了这些信息:

MongoDB: Combine data from multiple collections into one..how?

Merge two collections on mongodb

Merging two collections in MongoDB

MongoDB and “joins” [duplicate]

但他们没有帮助我,我的问题如下: 我有多个集合,所有这些集合都包含国家/地区信息,但来自不同来源的不同代码,如下所示: 集合:A

{
  "_id" : ObjectId("59378477c64086fff293008b"),
  "country_code_2_letter" : "AF",
  "country_code_3_letter" : "AFG",
  "country_name" : "Afghanistan"
},

收藏:B

{
  "_id" : ObjectId("59e6d1b705f5978143c46455"),
  "CountryCode" : "MA05110083",
  "CountryName" : "Afghanistan"
},

我想合并这两个集合,并有如下的1个集合:

{
  "_id" : ObjectId("59e6d1b705f5978143c46455"),
  "country_name" : "Afghanistan",
  "country_code_2_letter" : "AF",
  "country_code_3_letter" : "AFG",
  "CountryCodeCollectionB" : "MA05110083"
}

如果集合A上不存在"country_name" : "Afghanistan",则将整个数据添加到集合A,其中"CountryCode"更改为"country_name""CountryCode"更改为"CountryCodeCollectionB" PS: 我有JSON个文件和collection 因为我有另一个集合,每个月应该更新最简单的方式将被高度评价

0 个答案:

没有答案