如果没有密钥,是否可以将所有密钥从一个文档复制到另一个文档?

时间:2019-07-09 07:09:52

标签: python mongodb pymongo

我有一个健身锻炼数据库,其中包含一些力量练习。由于一项练习可以通过多种方式完成,因此我添加了一项基础练习 即_id:"BenchPressBothHands"和几个类似的练习,即_id:"BenchPressRightHand"derivedFrom:"BenchPressBothHands"

是否可以将文档中已存在的键以外的所有内容都从发件人_id:"BenchPressBothHands"复制到_id:"BenchPressRightHand"

伪代码:

for documents in col.find(): derivedFrom = documents.get('derivedFrom') if derivedFrom is not None: update document with everything from the derivedFrom-document except the keys which already exists.

0 个答案:

没有答案