我有订单结构:
{u'order_id': 12341,
u'status_history': [{u'reason': u'',
u'status': u'2000',
u'time': datetime.datetime(2013, 7, 31, 11, 52, 47)},
{u'reason': u'',
u'status': u'6020',
u'time': datetime.datetime(2013, 7, 31, 11, 59, 8)},
]
}
我想要更新记录。我的问题:
problem_index = 1 # int
db.order.update({'order_id':order_id},
{'$set':{'status_history.%s' % problem_index : edited_item}}
)
结果:
AttributeError("'unicode' object has no attribute 'subtype'",)
为什么?
答案 0 :(得分:0)
哦..递归结构。需要更多关注。 我保存上一个版本:
last_item = edited_item
# Need last_item = copy.copy(edited_item)
if edited_item.has_key('previous versions'):
edited_item['previous versions'].append(last_item)