Storing MongoDB with Objects

107 views
Skip to first unread message

jason stewart

unread,
Aug 18, 2014, 7:30:44 PM8/18/14
to chica...@googlegroups.com
I am trying to add an bson object to a field in my mongodb database using bossRecord

Model

     -module(clientList, [Id, Listname, Email, Datablock]).
     -compile(export_all).

Code

    ClientList = clientList:new(id, "Bill","bi...@email.com",{{"0","Field1"},{"1","Field2"},{"2","Field3"}})
    boss_db:transaction ( fun()-> ClientList:save() end).

Error

    [error] Error in controller error undef


I understand that a bossRecord is not the same as a bson object, but I am unsure how to get it in there, is there a converter, do I need to create a new boss record.

Also if anyone know any site that explains anything to do with Chicago boss database access could you let me know, I am finding that the documentation for it is useless or its just  I am not getting it

Kai Janson

unread,
Aug 18, 2014, 10:43:01 PM8/18/14
to chica...@googlegroups.com
Hi Jason,

Try your saving without the transaction.

--Kai 

Sent from my non-google-device
--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/7c6c4513-aebd-4c1b-bf9f-7747220f7187%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jason stewart

unread,
Aug 18, 2014, 11:25:54 PM8/18/14
to chica...@googlegroups.com
Hi Kia,

I changed the save

ClientList:save().

Now I get an error that looks like this

[error] gen_server <0.285.0> terminated with reason: no function clause matching bson_binary:put_field_accum("Field1", "Name", <<>>) line 93

can2nac

unread,
Aug 19, 2014, 1:48:18 PM8/19/14
to chica...@googlegroups.com
try [{"0","Field1"},{"1","Field2"},{"2","Field3"}]

jason stewart

unread,
Aug 20, 2014, 6:18:24 PM8/20/14
to chica...@googlegroups.com
I tried that with

ClientList = clientList:new(id, "Bill","bi...@email.com",{{"0","Field1"},{"1","Field2"},{"2","Field3"}})

but then I get a bson error message

[error] Error in controller error function_clause [{bson_binary,put_field_accum,["0","Field1",<<>>],[{file,"src/bson_binary.erl"},{line,93}]}

Kai Janson

unread,
Aug 20, 2014, 6:49:10 PM8/20/14
to chica...@googlegroups.com
Care to share your model and controller code in question?

Sent from my non-google-device
--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.

jason stewart

unread,
Aug 21, 2014, 7:32:47 PM8/21/14
to chica...@googlegroups.com
As you can see there is not much to it, a very simple insert 

Model

------

-module(clientList, [Id, Listname, Email, Datablock]).
-compile(export_all).
-------

Controller
--------
-module(pigeon_mdbtest_controller, [Req]).

-export([hello/2]).

hello('GET', [])->
            ClientList = clientList:new(id, "Bill","bi...@email.com",[{"0","Field1"},{"1","Field2"},{"2","Field3"}]),
            boss_db:transaction ( fun()-> ClientList:save() end),
            {output, ["test done"]}.
------

Error
------

[error] Error in controller error function_clause
 [{bson_binary,put_field_accum,
              ["0","Field1",<<>>],
              [{file,"src/bson_binary.erl"},{line,93}]},
 {bson,doc_foldlN,5,[{file,"src/bson.erl"},{line,37}]},
 {bson_binary,put_document,1,
              [{file,"src/bson_binary.erl"},{line,91}]},
 {bson_binary,put_field,2,
              [{file,"src/bson_binary.erl"},{line,33}]},
 {bson_binary,put_value_accum,2,
              [{file,"src/bson_binary.erl"},{line,115}]},
 {lists,foldl,3,[{file,"lists.erl"},{line,1261}]},
 {bson_binary,put_array,1,
              [{file,"src/bson_binary.erl"},{line,112}]},
 {bson_binary,put_field,2,
              [{file,"src/bson_binary.erl"},{line,34}]}]


-------

Kai Janson

unread,
Aug 21, 2014, 7:38:49 PM8/21/14
to chica...@googlegroups.com
I might be totally off but I think you MUST use 

-compile(export_all).

as well here (due to the magic of the parse_transform step)



Sent from my tricorder

jason stewart

unread,
Aug 22, 2014, 7:41:08 AM8/22/14
to chica...@googlegroups.com
Nah didn't work export_all gave me the same error

I am starting to think that the logic is right as a Chicago boss database abstraction, but the libraries for mongoDB have a problem, tuples are not converting to bson object
I have tried with mock database and that works fine (correct me if I am wrong, is a mnesia db in memory).

Graeme Defty

unread,
Aug 22, 2014, 10:11:23 AM8/22/14
to chica...@googlegroups.com
Jason,

This may not be your problem, but . . . bear in mind that boss_db does not support the storage of arbitrary erlang terms in a boss db field - check the documentation here http://www.chicagoboss.org/api-record.html to see what is supported. (It may be that your bson falls under the category of 'binary' in which case you should not have an issue), Now, although that is the OFFICIAL (i.e. documented) position, CB does not do anything to prevent it, so it depends on the adaptor for the particular db you are using. The Mnesia adaptor does, but that is because Mnesia runs in erlang. It is quite possible that the Mongo adaptor does not support this behaviour.

I should point out that my experience is all with Mnesia. Perhaps someone who knows Mongo better than I can help you with your real problem. LoL

graeme






--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.

can2nac

unread,
Aug 22, 2014, 10:41:02 AM8/22/14
to chica...@googlegroups.com
works like magic

%clients.erl
-module(clients, [Id, Listname, Email, Datablock]).
-compile(export_all).

(rahm@can2nac-laptop)14> (clients:new(id,"Bill","te...@test.com",[{'1',<<"Field1">>},{two,"two"},{three,3}])):save().    
{ok,{clients,"clients-53f75484b3769c0ec200000b","Bill",
             "te...@test.com",
             [{'1',<<"Field1">>},{two,"two"},{three,3}]}}
(rahm@can2nac-laptop)15> boss_db:find("clients-53f75484b3769c0ec200000b").
{clients,"clients-53f75484b3769c0ec200000b",<<"Bill">>,
         <<"te...@test.com">>,
         [{'1',<<"Field1">>},{two,"two"},{three,3}]}


pay attention to Keys
Reply all
Reply to author
Forward
0 new messages