Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7183987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:06:28+00:00 2026-05-28T18:06:28+00:00

I’m trying to create an ejabberd module which uses mongodb-erlang as the driver. I’m

  • 0

I’m trying to create an ejabberd module which uses mongodb-erlang as the driver.

I’m doing this as follows:

  1. ejabberd starts my module, which starts a child process with gen_server
  2. I start mongodb application and setup a replset pool

    Replset = {<<"rs1">>, [{localhost, 27017}, {localhost, 27018}]},
    PoolSize = gen_mod:get_opt(poolsize, Opts, 2),
    Pool = resource_pool:new(mongo:rs_connect_factory(Replset), PoolSize),
    
  3. to get access to the pool, I insert the pool into an ets table

    try ets:new(mymodule_pool, [named_table, public]) of
            mymodule_pool -> ok
    catch
            _:_ -> alredy_existing
    end,
    ets:insert(mymodule_pool, {pool, Pool}),
    
  4. when my registered hook gets called by ejabberd, I fetch the pool and a connection from it

    Pool = element(2, lists:nth(1, ets:lookup(mod_log_chat_mongodb_pool, pool))),
    {ok, Conn} = resource_pool:get(Pool),
    
  5. then I try to insert the new doc. This is where it fails

    mongo:do(unsafe, master, Conn, Db, fun() ->
            mongo:insert(Coll, Doc)
    end),
    

This is the error I get:

    {badarg,
     [{ets,
            update_counter,
            [mongodb_app,
             requestid_counter,
             1]},
            {mongodb_app,
             next_requestid,0},
            {mongo_connect,
             '-messages_binary/2-fun-0-',
             3},
            {lists,foldl,3},
            {mongo_connect,
             call,3},
            {mongo_query,
             find_one,2},
            {mongo_query,
             command,3},
            {mongo_replset,
             connect_member,2}]}

And from erlang.log:

    =CRASH REPORT==== 25-Jan-2012::16:01:23 ===
      crasher:
        initial call: mymodule:init/1
        pid: <0.289.0>
        registered_name: mymodule_localhost
        exception exit: {badarg,[{ets,update_counter,
                              [mongodb_app,requestid_counter,1]},
                         {mongodb_app,next_requestid,0},
                         {mongo_connect,'-messages_binary/2-fun-0-',3},
                         {lists,foldl,3},
                         {mongo_connect,call,3},
                         {mongo_query,find_one,2},
                         {mongo_query,command,3},
                         {mongo_replset,connect_member,2}]}
          in function  gen_server:terminate/6
        ancestors: [ejabberd_sup,<0.36.0>]
        messages: []
        links: [<0.210.0>]
        dictionary: []
        trap_exit: false
        status: running
        heap_size: 1597
        stack_size: 24
        reductions: 1182
      neighbours:

I tried a lot of different things but I don’t have a clue why this fails.
In ets:update_counter manual is the reason for badarg errors described as follows:

  • the table is not of type set or ordered_set,
  • no object with the right key exists,
  • the object has the wrong arity,
  • the element to update is not an integer,
  • the element to update is also the key, or,
  • any of Pos, Incr, Threshold or SetValue is not an integer

The relevant code of mongodb_app is as follows:

    %@doc Create global vars which will be owned by this supervisor (and die with it)
    init ([]) ->
            ets:new (?MODULE, [named_table, public]),
            ets:insert (?MODULE, [
                    {oid_counter, 0}, 
                    {oid_machineprocid, oid_machineprocid()},
                    {requestid_counter, 0} ]), 
            {ok, {{one_for_one,3,10}, []}}.

    %% API functions

    -spec next_requestid () -> mongo_protocol:requestid(). % IO
    %@doc Fresh request id
    next_requestid() -> ets:update_counter (?MODULE, requestid_counter, 1). 

I hope someone can help me for this, I’m helpless 🙁

Thank you very much,
Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:06:30+00:00Added an answer on May 28, 2026 at 6:06 pm

    I took a quick look at mongodb_app and I suspect one of two things.

    The first thing I suspect is that mongodb_app isn’t actually running. Run this in debug or live mode and make sure mongodb_app is in the list.
    application:which_applications().

    If it isn’t then make sure that application:start(mongodb_app) is in
    your module startup. If that is in your module start function then it
    is probably time to check the return value of the application:start(mongodb_app).

    The second thing I suspect is that there is a problem with the ets table. Investigate the status of the table with
    ets:info(mongdb_app). and ets:tab2list(mongdb_app).

    mongdb_app:init() declares the table as a public table so
    there shouldn’t be any owning process issues. I’m not sure what else
    to suggest other than debugging the state of the mongodb_app ets table and
    working your way back into your code from any clues you find there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.