创建了一个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:
有什么想法?
我使用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"
}