I am trying to understand the boss_db module to access the mongodb I have setup in Chicago boss
I found an example to access that data using boss_db from Here
example:
Puppy = boss_db:find("puppy-1"),
io:format("Puppy's name: ~p~n", [Puppy:name()]).
but when I try this all with my code
Cl= boss_db:find(clientList, [], [{limit,1}]),
io:format("Puppy's name: ~p~n", [Cl:datablock()]),
I get this error message
[{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}]}]
I know I am getting returned data cos I can do
[{clientList, _,_,_, Datablock}] = boss_db:find(clientList, [], [{limit,1}]),
io:format("data block is : ~p~n", [Datablock]).
and it comes back without a problem
My preference would be to find it by a field name and not pattern matching as the pattern may change at some point.
am I looking at old examples or is it that this example only works with relational db. I am having trouble finding site that has some simple examples on how to do this
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