PoolSize in Ecto MongoDB

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.

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!