Since last two days I have been trying to sort and/or filter documents in pouchdb using a plugin relational-pouch but its not working for some reason
I have read the docs from Pouch DB's official documentation and followed the steps, i.e, I created an index and then called the find('type',options) method with document type and options as given in the code below, but the results I get is ordered by id's, the tricky part is I can pass the "limit" option in the options and it works but on the same place "sort" option doesen't seems to work, also it would be help full if someone can point me to a place where I can find how to filter in relational-pouch, the official GitHub docs won't help
get() {
this.db.createIndex({
index: {
fields: ['title']
}
}).then((data)=>{
this.db.rel.find('content', {
limit : 1,
sort: ['title']
}).then((data)=>{console.log(data)});
}).catch(console.log)
}
// the schema applied
this.db.setSchema([
{singular: 'user', plural: 'users', relations: { contents: {hasMany: 'content'}}},
{singular: 'content', plural: 'contents', relations: { user: {belongsTo: 'user'}}}
]);
I am expecting results which are ordered by title(i even tried ordering by created), but I am getting the following:
{title: "Test title 5", description: "Test description 5", created: "2018-12-20T02:44:59.127Z", modified: "2018-12-20T02:44:59.127Z", id: "2A57FB9C-4E29-590C-AA4E-751FAA0F0AD9", …}
{title: "Test title 2", description: "Test description 2", created: "2018-12-19T03:40:56.302Z", modified: "2018-12-19T03:40:56.302Z", id: "2F568411-D955-42ED-9622-1C191AD6532D", …}
{title: "Test title 4", description: "Test description 4", created: "2018-12-20T02:44:51.654Z", modified: "2018-12-20T02:44:51.654Z", id: "319D2427-5862-477A-AAEA-CB2536C2430E", …}
{title: "Test title 1", description: "Test description 1", created: "2018-12-19T03:40:50.166Z", modified: "2018-12-19T03:40:50.166Z", id: "4D982FA6-99A9-4545-BC10-CBEF9530B3FA", …}
{title: "Test title 6", description: "Test description 6", created: "2018-12-20T02:45:06.927Z", modified: "2018-12-20T02:45:06.927Z", id: "7C4637AB-B626-E5FD-9353-5A7F926B98ED", …}
db.rel.save('author', { name: 'George R. R. Martin', id: 1, books: [6, 7] }etc., etc, ), and examine the data structure thatrelational-pouchwrites to your database. Without a solid understanding of the structure you're going to go round and round in circles. If that does not help then, please edit your question to include examples of your raw data and the schema you applied to your database (using this.db.setSchema([{def},{def}, ...]);). - Martin Bramwell