执行一个简单的"发现"使用mongodb-erlang驱动程序

时间:2016-04-07 20:56:31

标签: mongodb erlang

我使用的东西似乎是维护最多的mongodb erlang驱动程序:https://github.com/comtihon/mongodb-erlang

但是,我无法执行简单的find操作。我是erlang的新手,所以我希望我能错过一些明显的东西。这是一个片段:

Database = <<"my_database">>,
case mc_worker_api:connect([{database, Database}]) of
  {ok, Connection} -> 
    io:format("~p~n", [Connection]),
    Cursor = mc_worker_api:find(Connection, <<"my_collection">>, {}),
    io:format("~p cursor: ~p~n", [self(), Cursor]),
    mc_cursor:close(Cursor);
  {error, Reason} -> io:format("unable to connect to ~p: ~p~n", [Database, Reason])
end.

最终我的代码崩溃了这个堆栈跟踪:

{"init terminating in do_boot",{badarg,[{ets,update_counter,[mongo_id_server,requestid_counter,{2,1,2147483647,0}],[]},{mongo_id_server,request_id,0,[{file,"/Users/robinmonjo/code/erlang/mx/_build/default/lib/mongodb/src/core/mongo_id_server.erl"},{line,28}]},{mc_worker_logic,'-encode_requests/2-fun-0-',3,[{file,"/Users/robinmonjo/code/erlang/mx/_build/default/lib/mongodb/src/connection/mc_worker_logic.erl"},{line,23}]},{lists,foldl,3,[{file,"lists.erl"},{line,1262}]},{mc_worker_logic,make_request,4,[{file,"/Users/robinmonjo/code/erlang/mx/_build/default/lib/mongodb/src/connection/mc_worker_logic.erl"},{line,60}]},{mc_connection_man,request_raw,4,[{file,"/Users/robinmonjo/code/erlang/mx/_build/default/lib/mongodb/src/connection/mc_connection_man.erl"},{line,29}]},{mc_action_man,read_one_sync,4,[{file,"/Users/robinmonjo/code/erlang/mx/_build/default/lib/mongodb/src/core/mc_action_man.erl"},{line,29}]},{mc_worker_api,sync_command,4,[{file,"/Users/robinmonjo/code/erlang/mx/_build/default/lib/mongodb/src/api/mc_worker_api.erl"},{line,224}]}]}}

任何指针都会非常感激。

1 个答案:

答案 0 :(得分:1)

找到解决方案,我误读了README并忘记启动应用程序:

application:start (bson),
application:start (crypto),
application:start (mongodb),