MDSLKTR / pouch-vue

Pouchdb bindings for Vue.js
MIT License
90 stars 17 forks source link

bug: sort does not work on pouch object #30

Open BananaAcid opened 5 years ago

BananaAcid commented 5 years ago

This does not work.

Error: Uncaught (in promise) Error: unknown operator "0" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all

...
data() {},
pouch: {

    posts() {
        return {
            sort: [{header_date: "desc"}]
        }
    }
}
MDSLKTR commented 5 years ago

I believe this should be a good example https://pouchdb.com/api.html#query_index

db.find({
  selector: {name: {$eq: 'Mario'}}
}).then(function (result) {
  // handle result
}).catch(function (err) {
  console.log(err);
});

From the docs: sort defines a list of fields defining how you want to sort. Note that sorted fields also have to be selected in the selector.

posts() {
        return {
            selector: {header_date: {"$gte": null}}
            sort: [{header_date: "desc"}]
        }
    }
BananaAcid commented 5 years ago

Translating the Pouch examples is not straight forward at first. Might be helpful to be at the readme (sorting, ignoring if null).

I found out, adding selector:{} does the correct sorting. On PouchDB. Does not on CouchDB.

Got confused by the readme example:

          selector: {type: "person"},
          sort: [{name: "asc"}],