S
S
soif2013-05-21 16:37:17
Erlang
soif, 2013-05-21 16:37:17

MongoDB driver for Erlang

Perhaps the question is stupid, but I just can’t get MongoDB to connect to an Erlang application. There is no experience of screwing something other than Monga either. Tried to do it in 2 ways:

1) Official guide

$ git clone git://github.com/mongodb/mongodb-erlang.git mongodb
$ cd mongodb
$ make

$ erl
1> code:lib_dir().
"/usr/lib/erlang/lib"

$ mkdir /usr/lib/erlang/lib/mongodb-master
$ cp -R deps ebin /usr/lib/erlang/lib/mongodb-master/

Yep, ok

erl -pa ebin deps/*/ebin

2> application:start(bson).
ok
3> application:start(mongodb).
ok

> Host = {localhost, 27017}.
> {ok, Conn} = mongo:connect(Host).
** exception error: undefined function mongo:connect/1 I

looked in mongo.erl and there really is no connect function, strange, maybe I don’t understand something ...

hmm, I tried my luck mongo:insert (foo, {x,1, y,2} ).
I thought there would be some kind of “no connection” error, but I got:

** exception error: {badrecord,context}
in function mongo:write/1 (src/mongo.erl, line 229)
in call from mongo:insert/2 (src/mongo.erl, line 78)
in call from mongo:insert/2 (src/mongo.erl, line 75)

I don't understand… (( 2) Created an empty OTP application, added {deps, [

to rebar.config {mongodb, ".*", {git, "git://github.com/mongodb/mongodb-erlang.git", {branch, "master"}}}
%%{bson, ".*", {git, "git://github.com/mongodb/bson-erlang.git", {branch, "master"}}}
]}.

[email protected]:~/try_mongo$ rebar get-deps compile
==> bson (get-deps)
==> mongodb (get-deps)
==> try_mongo (get-deps)
==> bson (compile)
==> mongodb (compile)
/home/soif/try_mongo/deps/mongodb/src/mongo.erl:333: syntax error before: '.'
/home/soif/try_mongo/deps/mongodb/src/mongo.erl:32: function add_user/3 undefined
/home/soif/try_mongo/deps/mongodb/src/mongo.erl:330: spec for undefined function mongo:add_user /3
ERROR: compile failed while processing /home/soif/try_mongo/deps/mongodb: rebar_abort

Lacks understanding of Erlang, please advise,

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tremax, 2013-05-21
@soif

In the test folder, and in it the file is mongo_SUITE.erl (https://github.com/mongodb/mongodb-erlang/blob/refactor/test/mongo_SUITE.erl), and there is an example of how to use it.
{ok, Connection} = mongo_connection:start_link({"127.0.0.1", 27017}, [])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question