2013-07-16 28 views
-1

我用Google搜索,並在搜索stackoverflow.There我發現這一點:如何刪除沙發數據庫中的文檔中的單個字段?

db.get('id', function (err, doc) { 
    var inside_key_values = doc.key_value_pair; 

    delete inside_key_values[key_to_delete]; 

    db.merge("document", { 
     key_value_pair: inside_key_values 
     }, function (err, res) { 
     console.log('New key value pairs saved') 
     }); 

}); 

在此,我怎麼能和我的field.My字段替換doc.key_value_pair就像 商機信息:「我們進入的東西」, 在某些情況下,我必須刪除此字段(鍵 - 值對)。是否上面的代碼工作..?

在此先感謝.....

+1

你有沒有嘗試過的領域?每次要更新CouchDB中的文檔時,都需要再次保存整個文檔(文檔不能就地修改)。所以,你需要做任何修改,然後保存。 – WiredPrairie

+0

謝謝..我做到了 – Divya

回答

0
First we have to get the document from database 
After that delete the required field using delete operator and then update the document like 

    delete doc.tradeinfo; 

這裏商機信息是,我想在文檔(DOC),刪除

相關問題