我正在尝试删除嵌套字典中值为0的键:
{
"keyA": {
"keyA1": 10,
"keyA2": 0,
"keyA3": 3,
},
"keyB": {
"keyB1": 2,
"keyB2": 6,
"keyB3": 0,
},
}
我已经尝试过使用.DELETE_FIELD
database.collection("cases").document("ari_test").update({
f"someMap": {
"keyA": {
database.field_path("keyA2"): firestore.DELETE_FIELD
}
}
})
我得到了错误:
ValueError: Cannot update with nest delete: FieldPath('someMap','keyA','`keyA2`')
我需要.get()
整个字典,用python更新它,然后在Firestore上覆盖整个地图吗?
答案 0 :(得分:1)
使用path with dot-notation更新嵌套字段,例如:
database.collection('cases').document('ari_test').update({
'someMap.keyA.keyA2': firestore.DELETE_FIELD
})