pouchdb通过startkey和endkey删除

时间:2019-05-25 00:33:27

标签: pouchdb

有没有一种方法可以使用角度的pouchdb中的startkey和endkey删除记录?我当前用于地理位置的pouchdb看起来像这样,很好。我遇到的最接近的问题是这个PouchDb - remove object inside document,但对我来说却没有解决。

我希望避免获取整个文档,而只是进行查询删除(我承认我是从sql pov中仅在某种地方删除它)。欢迎任何输入:

state_123
county_1_123
state_124

基本上,我想删除所有状态。

   db.allDocs(
  {
    startkey: "state_",
    endkey: "state_" + "\uffff",
    include_docs: true
  },
  function(err, response) {
    // handle err or response
    if (!err) {
      console.log("pouchdb states returned ", response);

      // i was thinking of finding a way to delete those
      // responses in an efficient way

      let deleteStates = [];
      response.rows.forEach(item => {
        let doc = item["doc"];
        doc['_deleted'] = true;
        deleteStates.push(doc);
        });

        vm.pouch.bulkDocs(deleteStates);

    } else {
      console.log("error getting states", err);
    }
  }
);

0 个答案:

没有答案