【发布时间】:2016-07-29 23:30:30
【问题描述】:
我正在使用 PouchDb 和插件 PouchDb-find 在离子网络应用程序中查询我的本地数据库。在几乎每个用例中,我在创建索引时都会收到以下警告:
{
"docs": {
...
},
"warning": "no matching index found, create an index to optimize query time"
}
从插件文档的示例开始,我收到此警告,所以我想知道我做错了什么。
这是一个例子:
var db = new PouchDB('test');
var docs = [];
for (var i = 0; i < 10; i++) {
docs.push({title: 'Lorem ipsum ' + i, _id: 'doc' + (i + 1)});
}
db.bulkDocs(docs)
.then(
function () {
return db.createIndex({index: {fields: ['title']}});
})
.then(
function () {
// return db.find({selector: {title: {$eq: 0}}}); // No warning
return db.find({selector: {title: {$ne: 0}}}); // Warning
})
.then(
function (res) {
console.log(res);
})
.catch(console.error.bind(console));
为什么在使用$eq 时使用索引而不使用$ne?
然后,我有以下查询的更复杂的情况(假设'a.deep.property' 始终存在并且是一个数组):
db.find(
{
selector: {
$not:{
"a.deep.property": {$size:0}
}
}
}
);
我已经使用字段'a.deep.property' 创建了一个索引。也不使用索引。我需要创建什么索引?
我也尝试手动创建索引并在前一种情况下使用query(),但这比使用 PouchDb-find 慢。
有什么想法吗?
【问题讨论】:
标签: pouchdb