我正在使用来自couchDB的pouchDB复制本机。这是我的package.json:
"pouchdb": "^6.3.4",
"pouchdb-find": "^6.3.4",
"pouchdb-react-native": "^6.3.4",
我有一个名为“databaseA”的数据库,其中一列是“col1”。我使用pouchdb-find编写了一个查询来获取带有匹配的databaseA的所有记录 col1中的值。
const localDB = new PouchDB('databaseA');
const remoteDB = new PouchDB('databaseA');
PouchDB.plugin(findPlugin);
localDB.replicate.from(
remoteDB,
(err, response) => {
if (err) {
return console.log(err);
}
},
);
localDB.createIndex({
index: {
fields: ['col1', 'col2'],
ddoc: 'col1-col2-index',
},
});
localDB.find({
selector: {
col1: {
$eq: '1',
},
col2: true,
},
fields: ['_id', 'col1', 'col2' ],
limit: 0,
// sort: [‘_id’],
use_index: 'col1-col2-index',
}).then((results) => {
alert(`Index called to increase speed: ${results.docs.length}`);
}).catch((ex) => {
// alert(`Index called to increase speed: Exception: ${JSON.stringify(ex)}`);
});
export function getItems(col1) {
const startTime = new Date();
return (dispatch, getState) => {
return localDB.find({
selector: {
col1: {
$eq: col1,
},
col2: true,
},
fields: ['_id', 'col2', 'col1' ],
// sort: [‘_id’],
use_index: 'col1-col2-index',
}).then((results) => {
const time = new Date().getTime() - startTime;
alert(`Total time ${time}`);
}).catch((ex) => {
console.log(ex);
});
};
}
我在数据库中有大约900条记录。它需要将近2分钟才能查询。如何提高此查询的性能?请帮忙