0

我正在尝试第一次尝试从 erlang 写入 mongodb,并遇到使用此处找到的 mongodb_erlang 驱动程序的建议。但是,我创建了一个非常简单的模块,类似于 repo 中的一个测试:

-模块(mongo_test)。
-编译(export_all)。


初始化()->
    应用程序:开始(bson),
    应用程序:开始(mongodb)。

insert_and_find() ->
    主机 = {localhost, 27017},
    Conn = mongo_connection:start_link(Host, []),
    数据库 = 棒球,
    收藏=团队,
    Teams = mongo:do(safe, master, Conn, Database, fun() ->
                                                           mongo:插入(集合,[
                                                                                     {name, >, home, {city, >, state, >}, League, >},
                                                                                     {name, >, home, {city, >, state, >}, League, >},
                                                                                     {name, >, home, {city, >, state, >}, League, >},
                                                                                     {name, >, home, {city, >, state, >}, League, >}
                                                                                     ]),
    4 = mongo:count(集合, []),
    团队 = 查找(集合,{}),

    国家队 = [球队 || 团队 >],
    NationalTeams = find(Collection, {league, >}),
    2 = mongo:count(Collection, {league, >}),

    TeamNames = [bson:include([name], Team) || 团队>,州,>}})
    结尾)。







%%私人的
查找(集合,选择器)->
    查找(集合,选择器,[])。
查找(集合,选择器,投影仪)->
    光标 = mongo:find(Collection, Selector, Projector),
    结果 = mongo_cursor:rest(Cursor),
    mongo_cursor:关闭(光标),
    结果。

但是,在调用 init() 启动 bson 和 mongodb 之后,我再调用 insert_and_find 并收到以下错误:

** 异常退出:{{function_clause,[{gen,call,
                                           [{好的,},
                                            '$gen_call',
                                            {请求,棒球,
                                                     {插入,团队,
                                                             [{姓名,>,家,
                                                                    {城市,>,州,>},
                                                                    联赛,>,'_id',
                                                                    {>}}]}},
                                            无穷],
                                           [{file,"gen.erl"},{line,146}]},
                                      {gen_server,call,3,[{file,"gen_server.erl"},{line,184}]},
                                      {mongo_connection,request,3,
                                                        [{file,"src/mongo_connection.erl"},{line,48}]},
                                      {mongo,write,4,[{file,"src/mongo.erl"},{line,251}]},
                                      {mongo,write,1,[{file,"src/mongo.erl"},{line,234}]},
                                      {mongo,insert,2,[{file,"src/mongo.erl"},{line,78}]},
                                      {mongo,insert,2,[{file,"src/mongo.erl"},{line,75}]},
                                      {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,573}]}]},
                    {gen_server,调用,
                                [{好的,},
                                 {请求,棒球,
                                          {插入,团队,
                                                  [{姓名,>,家,
                                                         {城市,>,州,>},
                                                         联赛,>,'_id',
                                                         {>}}]}},
                                 无穷]}}
     在函数 gen_server:call/3 中(gen_server.erl,第 188 行)
     从 mongo_connection:request/3 调用(src/mongo_connection.erl,第 48 行)
     来自 mongo:write/4 的调用(src/mongo.erl,第 251 行)
     来自 mongo:write/1 的调用(src/mongo.erl,第 234 行)
     从 mongo:insert/2 调用(src/mongo.erl,第 78 行)
     从 mongo:insert/2 调用(src/mongo.erl,第 75 行)

这个错误对我来说相当模糊,我无法在网上找到任何帮助。任何建议将不胜感激。

最好的。

4

1 回答 1

1

尝试替换:Conn = mongo_connection:start_link(Host, []),{ok, Conn} = mongo_connection:start_link(Host, []),

于 2013-05-20T06:10:24.467 回答