【发布时间】:2019-08-21 21:22:10
【问题描述】:
我希望使用 pouchdb 对结果进行排序/排序。 我在希望排序大于 882 的字段上创建了一个索引
我已检查数据库是否存在
那么结果是这样的:
883
895
9
909
917
93
我指的是文档:https://pouchdb.com/guides/mango-queries.html 和这个文档:http://docs.couchdb.org/en/stable/api/database/find.html
this.db= new PouchDB('parcelles', {adapter: 'idb'});
// Create an index to the field id_culture
this.db.createIndex({
index: {
fields: ['id_culture']
}
}).then((result)=> {
console.log(result);
}).catch(function (err) {
});
// Query with the sort filter
this.db.find({
selector: {
id_culture: {$gte: '882'}
},
sort: ['id_culture']
}).then( (result)=> {console.log(result);
}).catch(function (err) {console.log(err);
});
【问题讨论】:
-
这些字段排序正确,它们只是按文本表示排序,而不是按数值排序。要按数值排序,最简单的选择是用前导零填充数字。