mmmrrr

mmmrrr

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}])

First Post!

beepbeepbopbop

beepbeepbopbop

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.

Where Next?

Popular in Questions Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

We're in Beta

About us Mission Statement