我正在尝试了解boss_db模块以访问我在芝加哥老板设置的mongodb
我找到了一个使用Here
中的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]).
它没有问题就回来了
我的偏好是通过字段名称找到它而不是模式匹配,因为模式可能会在某些时候发生变化。
我正在查看旧示例,或者这个示例仅适用于关系数据库。我找不到有关如何执行此操作的简单示例的网站答案 0 :(得分:1)
您引用的代码使用boss_db:find / 1返回记录。您的代码使用Boss_db:find / 3返回记录列表。
上面的示例,使用我的数据库,重现了问题
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,[])
但是认识到boss_db返回一个列表,并且一切正常:
1> [CL]= boss_db:find(customer, [], [{limit,1}]).
... snip ...
2> CL:id().
"customer-1"
希望这有帮助