[erlang-questions] ** exception error: bad argument in function ets:lookup_element/3

103 views
Skip to first unread message

raviraj555

unread,
Dec 20, 2011, 7:29:49 AM12/20/11
to erlang-q...@erlang.org
Hi All,
I m new in Erlang, when i do the mongodb connection it get connected
successfully but if run any query inside function i m getting
following error

hello_
** exception error: bad argument
in function ets:lookup_element/3
called as ets:lookup_element(mongodb_app,oid_machineprocid,2)
in call from mongodb_app:gen_objectid/0
in call from mongo:assign_id/1
in call from lists:map/2
in call from mongo:insert_all/2
in call from mongo:insert/2
in call from mongo:do/5
in call from art:run/0

for reference this is my code


run() ->
application:start(mongodb),
{ok, Conn} = mongo:connect({localhost, 27017}),
{ok, Docs} = mongo:do (safe, master, Conn, test, fun() ->
io:fwrite("hello_"),
mongo:delete (foo, {}),
mongo:insert (foo, {x,1, y,2}),
mongo:find (foo, {x,1}) end),

mongo:disconnect (Conn).
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Jesper Louis Andersen

unread,
Dec 20, 2011, 8:04:29 AM12/20/11
to erlang-q...@erlang.org
On 12/20/11 1:29 PM, raviraj555 wrote:
> Hi All,
> I m new in Erlang, when i do the mongodb connection it get connected
> successfully but if run any query inside function i m getting
> following error
>
> hello_
> ** exception error: bad argument
> in function ets:lookup_element/3
> called as ets:lookup_element(mongodb_app,oid_machineprocid,2)
> in call from mongodb_app:gen_objectid/0
> in call from mongo:assign_id/1
> in call from lists:map/2
> in call from mongo:insert_all/2
> in call from mongo:insert/2
> in call from mongo:do/5
> in call from art:run/0
The problem is that ets:lookup_element/3 returns badarg because
something you passed to that function is not valid. Most likely, the
problem is that there is no 'mongodb_app' ETS table created. My guess is
that you need to application:start(mongodb) or something such which will
initialize the table correctly. In other words the mongodb application
has some initialization assumption which has not been run yet.

Hope this helps!

--
Jesper Louis Andersen
Erlang Solutions Ltd., Copenhagen, DK

Reply all
Reply to author
Forward
0 new messages