Issue #10 resolved

Does EMongo support group function

Anonymous created an issue


Does Emongo support group function? If not, is it something that has been worked on?


Comments (5)

  1. Dmitry Belyaev repo owner

    It doesn't yet have helper but in my code I use it like this:

    emongo:find_one(?POOL, "$cmd",
                                     [{<<"ns">>, ?TABLE},
                                      {<<"key">>, [{<<"f">>, true}, {<<"t">>, true}]},
                                      {<<"cond">>, [{<<"k">>, [{<<"$exists">>, true}]}]},
                                      {<<"initial">>, [{<<"i">>, 0}]},
                                      {<<"$reduce">>, <<"function(obj, acc){acc.i = 1;}">>}

    Of course, I'm planning to add helper for this.

  2. Anonymous

    I tried what you said and could not get it to work. Could you provide a more detailed example?

    Thanks for your response.

  3. Dmitry Belyaev repo owner

    What fields do you have and what do you want to have in result?

    ns is your collection name, key is proplist of fields you'll group on cond is just a selector (like in find_all)

    initial is initial object you get in resuce function, just like lists:foldl(ReduceFunction, InitialValue, ValueList).

  4. Anonymous

    Thanks, that helps me realize what I did wrong. My program is working now. My mistake was that I put collection name on the place where "$cmd" is suppose to be. My bad.

    Thanks again for your help.

  5. Log in to comment