使用 pouchdb 删除和更新

delete and update using pouchdb

hye huys,我需要有关使用 pouchdb 进行删除和更新的帮助。现在创建和读取数据可以工作。只是删除和更新还不行。 这是我的数据库

application.service('Database', ['$q', '$window',
function($q, $window)
{
    var db = new $window.PouchDB('web-sample');

    this.delete = function(documentId, documentRev, options)
    {
        return $q.when(db.delete(documentId, documentRev, options));
    };

    this.get = function(documentId)
    {
        return $q.when(db.get(documentId));
    };
}

]);

这是我的服务

application.service('Arrears', ['$q', 'Database',
function($q, Database)
{
    this.remove = function(documentId, documentRev, options)
        {
          return Database.delete(documentId, documentRev, options);
        };


    this.update = function()
    {
        return Database.update()
    };
}

]);

这是我的控制器。

application.controller('ArrearsManagementReadAllController', ['$location', '$mdSidenav', '$routeParams', '$scope', 'arrears',
function($location, $mdSidenav, $routeParams, $scope, arrears)
{
    $scope.arrears = arrears;
    $scope.remove = function(id)
    {
        $location.path('/arrears_management/all');
    };

    var arrears = {
        owner_name: '',
        owner_id: '',
        account_no: '',
        title_no: '',
        address: '',
        house_no: '',
        floor: '',
        lot: '',
        block: '',
        locality: '',
        total_outstanding: '',
        last_receipt_no: '',
        last_pay_date: '',
        last_paid_amount: '',
    };

    var actions = {};

    actions.submit = function(arrears)
    {
        Arrears.update(arrears).
            then(function(response)
            {
                $location.path('/arrears_management/all');
            });
    };
}]);

如果你们都知道如何解决我的问题,请评论。谢谢

尝试删除时,您可能会遇到冲突,因此可能需要重试删除,但在使用递归调用时,使用计数器进行一定次数的重试,然后抛出错误,捕获结果,如果它由于冲突以外的其他原因无法删除。

同样,尝试更新时,您需要先获取最新的文档修订版,然后再尝试放置。同样,您需要处理诸如 404 和 409 错误之类的冲突。如果您收到 404,请尝试在重试之前删除修订版。使用 409 只需重试。同样,如果使用递归调用,最好进行一定次数的重试,然后针对其他条件抛出错误并捕获结果。