我希望能够向要从主数据库查询的数据添加新字段。
如果我在下面运行以下代码:
database_connection = MongoClient(database_address)
collection = database_connection.db.collection
id_list = [1,2,3,4]
leads_list = []
for i in id_list[0:2]:
leads = list(collection.find({ 'prospects': int(i) }, {
'_id':0,
'created': 1,
'prospects': 1,
'tags': 1
}
))
leads_list.extend(leads)
我得到这个结果:
[{'tags': [],
'prospects': [1],
'created': datetime.datetime(2016, 9, 5, 14, 59, 2, 782000)},
{'tags': [],
'prospects': [1],
'created': datetime.datetime(2016, 12, 15, 7, 19, 48, 449000)},
{'tags': [],
'prospects': [2],
'created': datetime.datetime(2016, 12, 30, 6, 19, 36, 474000)},
{'tags': [],
'prospects': [2],
'created': datetime.datetime(2017, 5, 15, 17, 7, 59, 171000)},
{'tags': [],
'prospects': [3],
'created': datetime.datetime(2017, 6, 28, 1, 32, 6, 953000)},
{'tags': [],
'prospects': [4],
'created': datetime.datetime(2017, 10, 7, 7, 3, 42, 54000)}]
我想在其中添加一个新字段,并得到如下内容:
[{'id': 1
'tags': [],
'prospects': [1],
'created': datetime.datetime(2016, 9, 5, 14, 59, 2, 782000)},
{'id': 1
'tags': [],
'prospects': [1, 23],
'created': datetime.datetime(2016, 12, 15, 7, 19, 48, 449000)},
{'id': 2
'tags': [],
'prospects': [2],
'created': datetime.datetime(2016, 12, 30, 6, 19, 36, 474000)},
{'id': 2
'tags': [],
'prospects': [2, 34, 56],
'created': datetime.datetime(2017, 5, 15, 17, 7, 59, 171000)},
{'id': 3
'tags': [],
'prospects': [3, 35, 64],
'created': datetime.datetime(2017, 6, 28, 1, 32, 6, 953000)},
{'id': 4
'tags': [],
'prospects': [4, 12, 46],
'created': datetime.datetime(2017, 10, 7, 7, 3, 42, 54000)}]
再次感谢!单词单词单词单词单词