pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.37k stars 1.04k forks source link

Docs for sorts #139

Closed natew closed 7 years ago

natew commented 7 years ago

Case

Making it a bit easier to figure out indexing with RxDB

Issue

Been trying to create an index and sort by that index for a while with no luck.

I've tried a variety of things like this:

DB._adminPouch.createIndex({ index: { fields: ['doc4.created_at'] }}).then(console.log)

And then querying that collection using:

DB.collection({ ... }).then(col => col.find().sort({ created_at: 'asc' })).exec()).then(console.log)

With no luck so far, doing everything client side in the browser.

natew commented 7 years ago

Ahh figured this out,

DB.collection.pouch.addIndex

Also, I saw a post somewhere that auto-index adding was a thing. What are downsides of adding that?

Also generally docs on accessing pouch through collections would be 👍

pubkey commented 7 years ago

Yes. The _adminPouch is used internally and you have to touch myCollection.pouch for the pouchdb-instance of a collection. To add an index, you can set index: true in the schema, see here or compound-indexes like here.

It looks like this is missing in the docs, I'm sorry for that.

TODO add index and compound-index to docs