Read all the documents from a bucket

Is there a way to read all the documents from a bucket? It is an active bucket an I want to access newly created document as well.
Few people suggested to use to view to query against a bucket. How can I create a View which will be updated with new or updated documents?

Okay so if you want to have pull-based access to all of your documents you have two options:

  • Create a view which emits all ids and then load them through get() calls.
  • Perform a N1QL query (4.0+) which returns you all documents.

For real push access as the changes come in, there is DCP, but this is highly experimental up to this point for clients. You can also do a mixture, like poll your view every X seconds and such.

Does that help?

Yes. I am polling the database every 10 seconds. Can you help me writing the view?
Newly created view’s map function looks like this:
function (doc, meta) { emit(doc); }

Reduce function is empty.

When I run bucket.query(ViewQuery.from("test1", "all")).totalRows() it returns expected results to me.

That function looks okay, you also don’t need a reduce function for this.

  • Did you publish your view properly?
  • When you query it on the UI, do you get results?