如何在 pouchdb find 中访问手动创建的索引
How to access manually created index in pouchdb find
我对 pouchDB 和 couchDB 还很陌生。我正在尝试使用 pouchdb find 但遇到了一些问题。
我创建了视图 "test" 和源 -
function(doc) {
emit(doc.name, doc.occupation);
}
当我 运行 这个 -
localDB.query('test/test').then(function (res) {
console.log(res);
}).catch(function (err) {
console.log(err);
});
一切正常。
但是当我尝试 pouchdb 时发现 -
localDB.find({
selector: {name: 'kittens'}
}).then(function (result) {
console.log(result);
}).catch(function (err) {
console.log(err);
});
我收到以下错误 -
Error: couldn't find a usable index. try creating an index on: name.
如果我通过
创建索引
localDB.createIndex({
index: {
fields: ['name']
}
});
只有 pouchdb 才能找到代码。但是当我手动创建一个索引时(如上图所示)然后它没有。
感谢任何帮助。提前致谢。
pouchdb-find 使用新的 "Mango" 查询语言,这与 map/reduce 不同。 Mango 仅在 CouchDB 2.0+ 和 PouchDB 服务器中受支持,不 CouchDB 1.x.
因此,此时您需要使用 CouchDB 2.0 或带有 pouchdb-find 的 PouchDB 服务器,如果您希望它同时在客户端和服务器上运行,或者您需要使用常规 map/reduce相反,避免使用 pouchdb-find。
我对 pouchDB 和 couchDB 还很陌生。我正在尝试使用 pouchdb find 但遇到了一些问题。
我创建了视图 "test" 和源 -
function(doc) {
emit(doc.name, doc.occupation);
}
当我 运行 这个 -
localDB.query('test/test').then(function (res) {
console.log(res);
}).catch(function (err) {
console.log(err);
});
一切正常。
但是当我尝试 pouchdb 时发现 -
localDB.find({
selector: {name: 'kittens'}
}).then(function (result) {
console.log(result);
}).catch(function (err) {
console.log(err);
});
我收到以下错误 -
Error: couldn't find a usable index. try creating an index on: name.
如果我通过
创建索引localDB.createIndex({
index: {
fields: ['name']
}
});
只有 pouchdb 才能找到代码。但是当我手动创建一个索引时(如上图所示)然后它没有。
感谢任何帮助。提前致谢。
pouchdb-find 使用新的 "Mango" 查询语言,这与 map/reduce 不同。 Mango 仅在 CouchDB 2.0+ 和 PouchDB 服务器中受支持,不 CouchDB 1.x.
因此,此时您需要使用 CouchDB 2.0 或带有 pouchdb-find 的 PouchDB 服务器,如果您希望它同时在客户端和服务器上运行,或者您需要使用常规 map/reduce相反,避免使用 pouchdb-find。