Skip to content
kotedo edited this page Apr 8, 2013 · 3 revisions

MongoDB Adapter

The MongoDB Adapter uses the mongodb-erlang driver.

It takes two specific options, db_write_mode and db_read_mode which can be used to configure write-mode and read-mode, as described in mongodb-erlang README file By default, write-mode is set to safe and read-mode is set to master.

In case you're using a MongoDB replSet, boss_db can be configured to use a replSet like this

{db_adapter, mongodb},
{db_replication_set,  {<<"rs0">>, [{localhost, 27017}, {localhost, 27018}, {localhost, 27019}]}},
{db_read_mode, slave_ok},

Replace "rs0" with the name of your replSet and exchange "localhost" for the server running your MongoDB replSet members. The option for db_read_mode allows for reading from the slaves vs. reading from the master. Keep in mind that depending on the location of the slaves it might be that you're getting old data. If you NEED 100% accurate data on read, use "master" instead of "slave_ok".

The adapter considers lists of integers and binaries as strings, so passing it values such as "hello" or <<"hello">> will result in a string object being stored in your database. If you actually need to store lists of integers, you will need to wrap them in a tagged tuple such as {integers, [1,2,3]} so that the adapter knows you really want to store a list of integers and not a string. A similar tuple will be returned when reading back from the database.

Raw queries can be made using execute/2 for things like MapReduce.

TODO: add raw queries examples.