Elixir ODM-like module for MongoDB
Elixir
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
README.md
mix.exs
mix.lock

README.md

Mongoex

Mongoex is an ODM-like module for MongoDb in Elixir.

This is still under development.

Usage

defmodule User do
  use Mongoex.Base
  fields name: nil, sex: nil, age: 20
end

iex> Mongoex.Server.setup(address: 'example.com', port: 27017, database: :your_app)
iex> Mongoex.Server.start

iex> user = User.new(name: "mururu", sex: :male, age: 22)
User[_id: nil, name: "mururu", sex: :male, age: 22]

iex> user.save
:ok

iex> mururu = User.find({:name, "mururu"})
User[_id: {<<80,130,218,110,117,35,125,79,90,0,0,1>>}, name: "mururu", sex: :male, age: 22]

iex> mururu.destroy
:ok

Options

You can authenticate by passing username and password options in the setup.

Mongoex can maintain a pool of connections that are created on server start. By default only one connction is created but you can change this by passing a pool option. If all connections are in use then a DB function will return

{:error, :no_available_connections}