从另一个Mongo集合中的另一个字段在Mongo对象上添加新字段

时间:2019-09-23 14:14:38

标签: python-3.x mongodb

我想制作一个python脚本,根据来自另一个集合public中一个字段的匹配,向我的teachers集合中的对象添加一个新字段。

我的public mongo集合看起来像:

{
  _id: 'a1',
  title: 'title stuff one',
  br_code: ['M333','L9876'],
},
{
  _id: 'a2',
  title: 'title stuff two',
  br_code: ['L9876','PR345'],
}

我的teachers mongo集合看起来像:

{
  _id: 'b1',
  br_code: ['M333','L9876'],
  br_code: ['unknown label','lunch time guidelines'],
},
{
  _id: 'b2',
  br_code: ['PR345'],
  br_label: ['children art book']
},
{
  _id: 'b3',
  br_code: ['L1234','L9876'],
  br_label: ['this is a label','lunch time guidelines']
}

我在public中所需的更新如下:

{
  _id: 'a1',
  title: 'title stuff one',
  br_code: ['M333','L9876'],
  br_label: ['unknown label','lunch time guidelines']
},
{
  _id: 'a2',
  title: 'title stuff two',
  br_code: ['L9876','PR345'],
  br_label: ['lunch time guidelines', 'children art book']
}

0 个答案:

没有答案