Getting no results from :couchbeam_changes.follow/2

I’m currently trying to build a toy application using CouchDB. For a specific use case I have in mind, I’d like to follow the changes feed of a specific database.

I tried to apply the examples from the :couchbeam repository in a livebook but I’m not receiving any messages from the changes feed. The code looks like this:

server = :couchbeam.server_connection(~c"http://localhost:5984", [{:basic_auth, {~c"admin", ~c"admin"}}])
:couchbeam.server_info(server)

{:ok, db} = :couchbeam.open_db(server, ~c"user_1")

changes_fun = fn stream_ref, f ->
  IO.puts("changes_fun called")
  receive do
    {^stream_ref, {:done, last_seq}} ->
      IO.puts("stopped, last seq is #{inspect(last_seq)}")
      :ok

    {^stream_ref, {:change, change}} ->
      IO.puts("change row #{inspect(change)}")
      f.(stream_ref, f)

    {^stream_ref, error} ->
      IO.puts("error ? #{inspect(error)}")
  end
end

options = [:continuous, :heartbeat, stream_to: self()]
{:ok, stream_ref} = :couchbeam_changes.follow(db, options)
changes_fun.(stream_ref, changes_fun)

When I use the follow_once/2 function I’ll get the expected results back. So I assume I’m doing something wrong regarding the retrieval of events.

Just for completeness this is working:

server = :couchbeam.server_connection(~c"http://localhost:5984", [{:basic_auth, {~c"admin", ~c"admin"}}])
:couchbeam.server_info(server)

{:ok, db} = :couchbeam.open_db(server, ~c"user_1")

:couchbeam_changes.follow_once(db, [{:since, 0}])

I presume you’re using this: couchbeam/doc/couchbeam_changes.md at master · benoitc/couchbeam · GitHub

The thing that stands out to me is that the message shape looks different:

{change, StartRef, Row :: ejson_object()}

I would imagine that it’s not doing anything as your receive block doesn’t align with that shape. Try adding the {:change, …, …} and see if that makes a difference.

Hej! Thanks for the reply. You’re right about the library - sorry for omitting that.

I tried translating the example from the Readme here GitHub - benoitc/couchbeam: Apache CouchDB client in Erlang which displays the shape you see in my first post. So I guess that the docs are inconsistent there…

But even with a catch all case in the receive block it doesn’t yield any results.