0

我正在尝试了解 boss_db 模块以访问我在芝加哥老板设置的 mongodb

我从这里找到了一个使用 boss_db 访问该数据的示例

例子:

Puppy = boss_db:find("puppy-1"),
io:format("Puppy's name: ~p~n", [Puppy:name()]).

但是当我用我的代码尝试这一切时

Cl= boss_db:find(clientList, [], [{limit,1}]),
io:format("Puppy's name: ~p~n", [Cl:datablock()]),

我收到此错误消息

[{erlang,apply,
     [[{clientList,"clientList-53e30e8b10af5d1503000287",
           <<"Sheet1">>,<<"Jason@email.com.au\n">>,
           <<131,108,0,0,0,3,104,2,107,0,6,70,105,101,108,100,49,
             107,...>>}],
      datablock,[]],
     []},
 {pigeon_greeting_controller,template,3,
     [{file,
          "/home/jason/pigeon/src/controller/pigeon_greeting_controller.erl"},
      {line,57}]},
 {boss_web_controller,call_controller_action,3,
     [{file,"src/boss/boss_web_controller.erl"},{line,363}]},
 {boss_web_controller,apply_action,4,
     [{file,"src/boss/boss_web_controller.erl"},{line,355}]},
 {boss_web_controller,execute_action_inner,9,
     [{file,"src/boss/boss_web_controller.erl"},{line,334}]},
 {boss_web_controller_handle_request,process_dynamic_request,
     4,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},
      {line,242}]},
 {boss_web_controller_handle_request,process_request,4,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},
      {line,228}]},
 {boss_web_controller_handle_request,set_timer,7,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},
      {line,148}]}]

我知道我收到了返回的数据,因为我可以做到

[{clientList, _,_,_, Datablock}] = boss_db:find(clientList, [], [{limit,1}]),
io:format("data block is : ~p~n", [Datablock]).

它回来没有问题

我的偏好是通过字段名称而不是模式匹配来查找它,因为模式可能会在某些时候发生变化。

我是在看旧的例子,还是这个例子只适用于关系数据库。我很难找到有一些关于如何做到这一点的简单示例的网站

4

1 回答 1

1

The code that you are referencing uses boss_db:find/1 which returns a record. Your code uses Boss_db:find/3 which returns a list of records.

Your example above, with my database, reproduces the problem

1> CL = boss_db:find(customer, [], [{limit,1}]).
... snip ...

2> CL:id().
** exception error: bad argument
 in function  apply/3
    called as apply([{customer,"customer-1","TEST1","First Test Customer",
                               "red",
                               {{2014,8,12},{15,7,21}},
                               ["2014",45,
                                ["0",56],
                                45,"12",32,"15",58,
                                ["0",55],
                                58,"21",46,"486989"]}],
                    id,[])

but recognizing that boss_db returns a list, and all works:

1> [CL]= boss_db:find(customer, [], [{limit,1}]).
... snip ...
2> CL:id().
"customer-1"

Hope this helps

于 2014-08-09T21:41:28.120 回答