rocha7778

rocha7778

Enable Mongodb log in Elixir application

Hi Family I am struggling to try to enable the mongo logs to show the queries that elixir sends to execute to mondo DB.

type or paste code here
defmodule PocketInformation.Application do
  
    use Application
  
    @impl true
    def start(_type, _args) do
      children =
        [
          {
            Mongo,
            [
              name: :mongodb,
              database: AppConfig.get_db_name(),
              hostname: AppConfig.get_db_host(),
              port: AppConfig.get_db_port(),
              username: AppConfig.get_db_user(),
              password: AppConfig.get_db_password(),
              log_queries: true ## is supposed that is set to true the logs queries will be shown
              
            ]
          }
        ] 
      opts = [strategy: :one_for_one, name: __MODULE__]
      Supervisor.start_link(children, opts)
    end
  end

I am using {:mongodb, "~> 1.0.0-beta.1"}, dependency.

I have tried using in my config file the following instruction :
config :mongodb, log_level: :debug ## not work
but not work

I have tried to use Mongo.logger.enable() ## got function Mongo.logger/0 is undefined or private

I have tried with : Application.put_env(:pocket_information, Mongo.Connection, log_queries: true) ## not work

but none of the options have worked so far.

Most Liked

al2o3cr

al2o3cr

What documentation suggests this option will work? I couldn’t find any mention of this in either mongodb or mongodb_ecto.

mongodb exposes a log option that expects a function (or MFA tuple) that is passed directly along to DBConnection.

mongodb_ecto exposes a log_level option that gets stashed in the adapter meta and then the connection uses that value to hook up the log option that mongodb expects

Even if you’re not using mongodb_ecto, the code in that last link could be helpful for writing your own function to pass as the log option to the bare mongodb driver.

Where Next?

Popular in Questions Top

jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
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
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
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
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement