PouchDb - remove object inside document

放肆的年华 提交于 2019-12-11 03:56:18

问题


I'm an Italian PouchDb and AngularJS Developer. My json document is:

{
   "_id": "6",
   "_rev": "3-f7283d7683cd6fb15753f494aad1d49f",
   "name": "Ivrea",
   "owners": [
       {
           "owner_id": 1,
           "name": "asdas",
           "address": "asdas",
           "gender": "Uomo",
           "type": "Assente",
           "notes": [
           ]
       },
       {
           "owner_id": 2,
           "name": "balbaba",
           "address": "blabla",
           "gender": "Uomo",
           "type": "Assente",
           "notes": [
           ]
       }
   ]
}

and after an ng-click action, I will delete owner_id: 2 object inside _id: 6 document. In API reference I found only document delete action, but not how to delete object inside document.

Thanks for your reply!!

Alessandro


回答1:


You just need to put() the main document back in the database after you remove an object from it. :)

db.get('foo').then(function (doc) {
  delete doc.whatever;
  return db.put(doc);
}).catch(function (err) { /* ... */ });


来源:https://stackoverflow.com/questions/25078521/pouchdb-remove-object-inside-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!