我在删除以前在云端数据库中的文档中保留的属性时遇到问题。看起来我应该在它上面保存一个新版本,没有那个属性。我有以下代码,它可以正常工作,保存对象,我得到一个新的_rev。但statistics
属性仍在持久化文档中。
如何删除持久属性?
// mixStatistics don't get persisted on the mix, so remove property as it goes through
// the save
let saveMixStatistic = mix.statistics;
delete mix.statistics ;
// -------------------------
this.userDb.put(mix).then(function (response) {
// handle response
console.log("mix saved");
mix._rev = response.rev;
}).catch(function (err) {
console.log(err);
});
// put mixStatistics back after the save
mix.statistics = saveMixStatistic;
答案 0 :(得分:1)
你可能会过早地放回mix.statistics
。在这种情况下,很可能在PUT发出HTTP请求之前重新添加。在PUT完成后你应该尝试重置它。例如:
let saveMixStatistic = mix.statistics;
delete mix.statistics ;
this.userDb.put(mix).then(function (response) {
// handle response
console.log("mix saved");
mix._rev = response.rev;
// put mixStatistics back after successful save
mix.statistics = saveMixStatistic;
}).catch(function (err) {
console.log(err);
// put mixStatistics back after failed save
mix.statistics = saveMixStatistic;
});