【问题标题】:How to query on PouchDB如何在 PouchDB 上查询
【发布时间】:2018-01-26 03:56:59
【问题描述】:

假设我的 pouchdb 中有这样的文件:

{
    "_id" : "685866641",
    "name" : "john",
    "age" : 56,
    "job" : "mason"
}

如何查询数据库以返回作业为 mason 的所有文档? (我正在使用离子)

【问题讨论】:

    标签: ionic-framework nosql pouchdb


    【解决方案1】:

    我不知道“离子”,但我一直在使用“pouchdb.find.js”:

    https://github.com/nolanlawson/pouchdb-find

    还有“pouchdb.quick-search.js”:

    https://github.com/pouchdb-community/pouchdb-quick-search

    【讨论】:

      【解决方案2】:

      正如比尔所说,您需要一个插件。一旦你安装了 pouchdb,我就会使用这些导入(我想我使用的是 6.3.2):

      // pouchdb stuff:
      import PouchDB from 'pouchdb';
      import PouchDBFind from 'pouchdb-find';
      

      那么你需要确保你在构造函数中初始化这个插件:

       constructor(
          public http: HttpClient, 
        ) {
          PouchDB.plugin(PouchDBFind);
        }
      

      一旦你以正常方式初始化数据库:

      initdb(dbname) { this.db = new PouchDB(dbname) }
      

      您可以像这样使用查找查询:

      getDataById = (snippetId) => {
            return new Promise((resolve, reject)=>{
                this.db.find({
                    selector: {
                        _id: snippetId
                    }
                }).then((res) => {
                    resolve(res.docs[0]);
                }).catch((err) => { 
                    reject(err);
                })
            })
        };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-20
        • 2023-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多