Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get it to work - (UndefinedFunctionError) function :invalid_message.exception/1 is undefined #186

Closed
dmarko484 opened this issue Jan 16, 2018 · 6 comments

Comments

@dmarko484
Copy link

dmarko484 commented Jan 16, 2018

I have Mongo defined under supervisor based on docs. Now any operation (Mongo.find, Mongod.insert_one etc. ) raises the same error as below. Any idea whats wrong here? (Elixir 1.5.3 on windows)

iex([email protected])3> cursor = Mongo.find(:mongo, "names", %{})
%Mongo.Cursor{coll: "names", conn: #PID<0.468.0>, opts: [slave_ok: true],
 query: %{}, select: nil}
iex([email protected])4> Enum.to_list(cursor)                     
** (UndefinedFunctionError) function :invalid_message.exception/1 is undefined (module :invalid_message is not available)
    :invalid_message.exception([])
    (db_connection) lib/db_connection.ex:926: DBConnection.checkout/2
    (db_connection) lib/db_connection.ex:742: DBConnection.run/3
    (db_connection) lib/db_connection.ex:1133: DBConnection.run_meter/3
    (db_connection) lib/db_connection.ex:636: DBConnection.execute/4
    (mongodb) lib/mongo.ex:413: Mongo.raw_find/5
    (mongodb) lib/mongo/cursor.ex:40: anonymous fn/6 in Enumerable.Mongo.Cursor.start_fun/6
    (elixir) lib/stream.ex:1270: anonymous fn/5 in Stream.resource/3
    (elixir) lib/enum.ex:1841: Enum.reverse/1
    (elixir) lib/enum.ex:2599: Enum.to_list/1

@ankhers
Copy link
Collaborator

ankhers commented Jan 16, 2018

Can you please show the supervisor where you are starting mongo?

@dmarko484
Copy link
Author

defmodule Web.Application do
  use Application

  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  def start(_type, _args) do
    import Supervisor.Spec

    # Define workers and child supervisors to be supervised
    children = [
      # Start the endpoint when the application starts
      supervisor(WebWeb.Endpoint, []),
      worker(Mongo, [[name: :mongo, database: "elixir_ph3", pool: DBConnection.Poolboy, hostname: "localhost"]]),

      # Start your own worker by calling: Web.Worker.start_link(arg1, arg2, arg3)
      # worker(Web.Worker, [arg1, arg2, arg3]),
    here it is ...

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Web.Supervisor]
    Supervisor.start_link(children, opts)
  end

  # Tell Phoenix to update the endpoint configuration
  # whenever the application is updated.
  def config_change(changed, _new, removed) do
    WebWeb.Endpoint.config_change(changed, removed)
    :ok
  end
end

@dmarko484
Copy link
Author

And here is a traceback when I start Mongo in iex. using

{:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/elixir_ph3")

iex([email protected])1> {:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/elixir_ph3")
{:ok, #PID<0.602.0>}
** (EXIT from #PID<0.600.0>) evaluator process exited with reason: an exception was raised:
    ** (KeyError) key :database not found in: [topology_pid: #PID<0.602.0>, connection_type: :client, url: "mongodb://localhost:27017/elixir_ph3", hostname: "localhost", port: 27017]
        (elixir) lib/keyword.ex:371: Keyword.fetch!/2
        (mongodb) lib/mongo/protocol.ex:30: Mongo.Protocol.connect/1
        (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
        (connection) lib/connection.ex:622: Connection.enter_connect/5
        (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
                     
Interactive Elixir (1.5.3) - press Ctrl+C to exit (type h() ENTER for help)
iex([email protected])2> [error] GenServer #PID<0.609.0> terminating
** (KeyError) key :database not found in: [topology_pid: #PID<0.602.0>, connection_type: :client, url: "mongodb://localhost:27017/elixir_ph3", hostname: "localhost", port: 27017]
    (elixir) lib/keyword.ex:371: Keyword.fetch!/2
    (mongodb) lib/mongo/protocol.ex:30: Mongo.Protocol.connect/1
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: Mongo.Protocol

@ankhers
Copy link
Collaborator

ankhers commented Jan 17, 2018

The :url key is only available on the master branch. Are you using master, or are you using the latest released version (0.4.3)?

@ankhers
Copy link
Collaborator

ankhers commented Jan 17, 2018

You have a mismatch on which pooling mechanism you are trying to use. You are starting this driver with pool: DBConnection.Poolboy, but when you are querying, you are not telling the query to use that pooling mechanism. You will need to query like Mongo.find(pid, "collection", %{}, pool: DBConnection.Poolboy)

#175 is a conversation surrounding this issue.

@ankhers ankhers closed this as completed Jan 17, 2018
@dmarko484
Copy link
Author

Ok, specifying pool did the trick ... thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants