2017-10-19 62 views
0

我很難找到使用mongo引擎刪除嵌入式文檔中的列表項的方法。從嵌入式文檔中刪除列表項MongoEngine

文檔結構:

{ 
    "_id" : "id", 
    "user" : ObjectId("xxxxxxx"), 
    "invoice" : false, 
    "coupon" : ObjectId("xxxxxxx"), 
    "date" : ISODate("2017-03-31T11:32:57.467Z"), 
    "orders" : [ 
     { 
      "products" : [ 
       ObjectId("xxxxxxx") 
      ] 
     } 
    ], 
    "shipping_address" : { 
    }, 
} 

採用這種結構,我想達到的目標,是要刪除的產品列表中訂單內嵌入文檔裏面的ID

有什麼想法?任何幫助將非常感激

+0

你怎麼能指望的輸出看? – GiantsLoveDeathMetal

+0

空的產品清單{orders:[{products:[]}]} –

回答

0

你可以這樣做:

for order in document['orders']: 
    if 'products' in order: 
     order['products'] = [] 

如果你快譯通張貼「文檔結構」是= document