Search code examples
rxdb

How to list all documents in an RxDB collection?


In RxDB, to list all documents in a collection on a remote db that has documents, I've tried:

 myCollection.dump()
  .then(json => console.dir(json));

and

myCollection.find().exec() // <- find all documents
  .then(documents => console.dir(documents));

from the documentation: https://rxdb.info/rx-collection.html#dump https://rxdb.info/rx-document.html#find

but both do a _find post with body:

{"selector":{"_id":{}}}

that return an empty docs [] array. That same _find selector executed outside of RxDB also returns an empty docs array.

If I add documents to the collection with myCollection.upsert(), the doc is added to the remote server and then appears as a response in the two above calls. But maybe only from what's stored in memory, as there's still this remote _find POST with an empty docs: [] response. So on a page refresh those list calls are empty again.

I'm using:

    "pouchdb-adapter-http": "7.0.0",
    "rxdb": "8.0.4",
    "rxjs": "6.3.3"

Solution

  • At this point of time, there is no RxDB support for remote collections. You can sync the remote database into your local collection and then run queries there. But it is not possible to send queries to remote and get the results, like what is done with pouchdb-http-adapter.

    UPDATE (2024): RxDB has a new remote storage plugin: https://rxdb.info/rx-storage-remote.html