Pouchdb-find + Cloudant:错误:未知运算符" 0" - 应该是其中之一

时间:2016-12-12 20:29:39

标签: pouchdb cloudant

创建了一个json索引并在cloudant仪表板上测试了一个查询。

{
  "selector": {
    "$and": [
      {
        "$and": [
          { "type": { "$eq": "user" }},
          {
            "$or": [
              { "user":         { "$eq": "Elvis" }},
              { "first_name":   { "$eq": "Elvis" }},
              { "middle_name":  { "$eq": "Elvis" }},
              { "last_name":    { "$eq": "Elvis" }}
            ]
          }
        ]
      },
      {
        "$not": {
          "$and": [
            { "type": { "$in": ["follower", "admin"] }},
            { "hive": { "$eq": "8049CF96-A4F2-D2BE-B014-AA4F72642F3F" }},
            { "user": { "$eq": "Elvis" }}
          ]
        }
      }
    ]
  },
  "fields": [
    "_id",
    "_rev"
  ],
  "sort": [
    {
      "_id": "asc"
    }
  ]
}

以上工作在仪表板上,但是当我通过pouchdb-find使用它时,会抛出如下错误:

Error: unknown operator "0" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type or $all
Stack trace:

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我将您的示例选择器与Cloudant数据库一起使用,但我没有收到错误:

var PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-find'));

var db = new PouchDB('https://reader.cloudant.com/aaa');
var s = {"selector":{"$and":[{"$and":[{"type":{"$eq":"user"}},{"$or":[{"user":{"$eq":"Elvis"}},{"first_name":{"$eq":"Elvis"}},{"middle_name":{"$eq":"Elvis"}},{"last_name":{"$eq":"Elvis"}}]}]},{"$not":{"$and":[{"type":{"$in":["follower","admin"]}},{"hive":{"$eq":"8049CF96-A4F2-D2BE-B014-AA4F72642F3F"}},{"user":{"$eq":"Elvis"}}]}}]},"fields":["_id","_rev"],"sort":[{"_id":"asc"}]};

db.find(s).then(function(d) {
  console.log(d);
}).catch(function(e){
  console.log(e);
});

请亲自尝试上述代码。作为参考,我的文档如下所示:

{
  "type": "user",
  "first_name": "Elvis",
  "middle_name": "",
  "last_name": "Presley",
  "user": "a",
  "hive": "aaa"
}