2017-02-11 79 views
0

我正在使用pouchdb构建电子框架的应用程序。我的数据库中的一些值正在随着时间的推移而发生变化,我希望在不更新每个新更新的情况下为它们创建新文档。这样我就想使用修订版,因为每次更新文档时都会从新创建修订版。如何使用pouchdb中的revision属性获取文档?

问题是如何使用其修订版获取文档。

感谢您的帮助提前。

回答

0

我能够自己解决问题。对于那些有同样问题的人,我在此发布我的解决方案:

var pdb = new PouchDB('./test20'); // init of database 

/* if I call function changes() it gives me the changes of a specific 
    with a specific ID*/ 

function changes() { 
    console.log("Currently in: changes()"); 
    var idPlayer = ""+localStorage.getItem("playerIDLocalStorage"); 

    pdb.get(idPlayer, {revs_info: true}).then(function (revs) { 
    var x = 0; 

    while(revs._revs_info[x].rev != null) { 
     var revision = ""+revs._revs_info[x].rev; 

     pdb.bulkGet({ 
     docs: [{id: idPlayer, rev: revision}], 
     include_docs: true 
     }).then(function (result) { 
     var doc = result.results[0].docs[0].ok; 
     console.log(doc.playerName); 
     }).catch(function (err) { 
     console.log("Error in subchanges(): "+err); 
     }); 
     x++; 
    } 
    }).catch(function (err) { 
    console.log("Error in changes(): "+err); 
    }); 
}