使用模型对象列表批量更新mongoengine

时间:2018-11-29 10:40:57

标签: mongodb mongoengine restframeworkmongoengine

我想使用mongoengine对mongodb进行批量更新。

我的文档如下:

{
    "phone_number":123,
    "calls": 5 
}

{    
    "phone_number":345,
    "calls": 4
}

现在我有一个要更新的电话号码列表。

phone_number_list = [123,345]

phones = Model.object(phone_number__in=phone_number_list)

# update each model object properties based on some logic
for phone in phones:
    phone.calls += 1

# after updating individual object of model, I want  to update the  list of models 
phones.update()

如何实现这样的目标? mongoengine有可能吗?

0 个答案:

没有答案