我正在使用 PouchDb 和插件 PouchDb-find 在 ionic Web 应用程序中查询本地数据库。几乎在每个用例中,当我创建索引时,我都会在查询时收到以下警告:
{
"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 慢。
任何想法 ?
$ne
目前不使用任何索引。你必须使用类似的东西$gt
or $lt
反而。例如。代替$ne: 0
你会做{$gt: 0, $lt: 0}
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)