dericop

dericop

Hi,

I’m using Ecto Mongodb and I want to configure a custom pool size in my plug project. I was testing a few solutions but i can’t do it successfully. Do you can help me?

This is my config.exs:

use Mix.Config

import_config "#{Mix.env()}.exs"

config :feature_flags, FeatureFlags.Repo,
       adapter: Mongo.Ecto,
       mongo_url: "mongodb://ip/db?"

This is my mix.exs:

defmodule FeatureFlags.MixProject do
  use Mix.Project

  def project do
    [
      app: :feature_flags,
      version: "0.1.0",
      elixir: "~> 1.9",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  def application do
    [
      extra_applications: [:logger, :plug_cowboy, :mongodb, :poolboy,:mongodb_ecto, :ecto],
      mod: {FeatureFlags.Application, []}
    ]
  end

  defp deps do
    [
      {:plug_cowboy, "~> 2.1"},
      {:poison, "~> 3.1"},
      {:mongodb, ">= 0.4.9"},
      {:mongodb_ecto, "~> 0.1"},
      {:poolboy, ">= 1.5.2"}
    ]
  end
end

This is my applications.exs:

defmodule FeatureFlags.Application do
  @moduledoc "OTP application spec for Feature Flags"

  use Application

  def start(_type, _args) do
    import Supervisor.Spec
    IO.inspect(DBConnection.Poolboy)


    children = [
      worker(FeatureFlags.Repo, []),
      # Use Plug.Cowboy to register the endpoint
      Plug.Cowboy.child_spec(
        scheme: :http,
        plug: FeatureFlags.AppRestEntryPoint,
        options: [port: Application.get_env(:feature_flags, :port)]
      )
    ]

    opts = [strategy: :one_for_one, name: FeatureFlags.Supervisor, pool_size: 40]
    Supervisor.start_link(children, opts)
  end
end

defmodule FeatureFlags.Repo do
  use Ecto.Repo, otp_app: :feature_flags
end

Thanks for your help.

First Post! Switch mode

zookzook

zookzook

Hi dericop

instead of using Ecto with MongoDB it is a better way to use the driver api without any additional layer.

Ecto is made for SQL and MongoDB is very different. But that’s a philosophical question. In my opinion, Ecto is not necessary for the use of MongoDB. An additional level between the driver and the program is superfluous because the MongoDB documents are returned as maps. If you prefer defstructs, you can convert the maps into such. Queries as SQL-DSL are more of a headache for MongoDB and are not useful. Why should one describe MongoDB queries as SQL?

SQL-Injection in MongoDB is hardly possible because the queries do not have to be expressed as a strings but as keyword lists or maps.

Example:

Mongo.find_one(:mongo, "accounts", %{username: name}, limit: 1)

In this case you are not able to fake the query, because the content of name is always treated as value whatever it is. You don’t need to escape values here.

Good luck!

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement