Skip to content

inaka/sumo_db_mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sumo_db_mongo

About

This is the MongoDB adapter for sumo_db that works for 2.x versions.

MongoDB

Install MongoDB

To install MongoDB please follow the instructions in this link: Install MongoDB.

Initial Configurations

Due to the fact that MongoDB comes with default configuration, we need to change some parameters required by sumo_db.

If sumo is giving you an error like exit with reason bad return value: <<"auth failed">> in context start_error, it means that your current MongoDB installation is using the SCRAM-SHA-1 authentication mechanism, so we need to change it to use MongoDB-CR following these steps:

//NOTE: USE REMOVE COMMANDS IN TEST DB ONLY, IF IN PRODUCTION USE UPDATE.
mongo
use admin
db.system.users.remove({})    <== removing all users
db.system.version.remove({}) <== removing current version
db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3  })

//Now restart the mongod and create new user then it should work fine.

// Taken from https://stackoverflow.com/a/31476552/2969462

Getting Started

To start use sumo_db with this MongoDB adapter sumo_db_mongo is pretty easy, you only has to follow these steps:

  1. Add sumo_db and sumo_db_mongo as dependencies in your project.

Using erlang.mk:

DEPS = sumo_db sumo_db_mongo

dep_sumo_db      = git https://github.com/inaka/sumo_db.git      0.5.0
dep_sumo_db_mongo = git https://github.com/inaka/sumo_db_mongo.git 0.0.1

Using Rebar:

{deps, [
  {sumo_db, {git, "https://github.com/inaka/sumo_db.git", {tag, "0.5.0"}}},
  {sumo_db_mongo, {git, "https://github.com/inaka/sumo_db_mongo.git", {tag, "0.0.1"}}}
]}.
  1. You need at least one doc/entity, let's use sumo_test_people_mongo as example.

    NOTE: if you use this entity, you'll need to include mixer to the dependencies list

  2. Provide the configuration file, e.g.: test.config.

  3. Now you can run your app and start using sumo from there.

Running sumo from Erlang console

Start the Erlang console, adding the path to your beams and config file

$ erl -pa ebin deps/*/ebin -config tests/test.config

Within the console:

> application:ensure_all_started(sumo_db_mongo).
15:18:39.914 [info] Application lager started on node nonode@nohost
15:18:39.964 [info] Application sasl started on node nonode@nohost
15:18:39.976 [info] Application emongo started on node nonode@nohost
15:18:39.995 [info] Application crypto started on node nonode@nohost
15:18:40.005 [info] Creating wpool ETS table
15:18:40.006 [info] Application worker_pool started on node nonode@nohost
15:18:40.010 [info] Application quickrand started on node nonode@nohost
15:18:40.011 [info] Application uuid started on node nonode@nohost
15:18:40.150 [info] Application sumo_db started on node nonode@nohost
15:18:40.155 [info] Application sumo_db_mongo started on node nonode@nohost
{ok,[syntax_tools,compiler,goldrush,lager,sasl,emongo,
     crypto,worker_pool,quickrand,uuid,sumo_db,sumo_db_mongo]}

% from here you can start using sumo

> sumo:find_all(sumo_test_people_mongo).
[]

Running Tests

  • Create a test database
use sumo_test
  • Create an user to access that DB.
db.createUser({user: "root", pwd: "pass", roles: [{role: "userAdmin", db: "sumo_test"}]})
  • Or use defaults and configure it on test/test.config file.

TODO

  • Make this adapter work with MongoDB 3.x

Contact Us

If you find any bugs or have a problem while using this library, please open an issue in this repo (or a pull request :)).

And you can check all of our open-source projects at inaka.github.io