in reply to Re: MongoDB Stored procedure from Dancer2
in thread MongoDB Stored procedure from Dancer2

Thanks for replay, yes i try to use the code mentioned in the example, because the javascript procedure are volatile (as disconnect they disappear and you need to insert again) i save them. problem is when you try to add a document as example say ({"_id"=> getNextSequence("comm-id") +,"year" => "2017"}) it work fine, getNexSequence javascript work fine. but if i call it from perl it is not recognized and executed, so id will be 'getNextSequence("comm-id")' string
  • Comment on Re^2: MongoDB Stored procedure from Dancer2

Replies are listed 'Best First'.
Re^3: MongoDB Stored procedure from Dancer2
by poj (Abbot) on Mar 28, 2017 at 17:51 UTC

    All I can suggest is the perl equivalent of the getNextSequence function

    my $filter = {'_id' => 'userid'}; my $update = { '$inc' => { 'seq' => 1} }; my $col = $db->get_collection('counters'); $col->update($filter,$update); my $id = $col->find_one($filter)->{'seq'}; print $id;

    You can probably use find_one_and_update() but it didn't work on my old version 0.45 of MongoDB

    poj

      Poj,

      your suggestion is the right way, i will start from here.

      I Just underline update is deprecated

      @4000000058db6ef81e84eb6c # *** DEPRECATION WARNING *** @4000000058db6ef81e84eb6c # @4000000058db6ef81e84eb6c # The 'update' method will be removed in a f +uture major release. @4000000058db6ef81e84ef54 # Use $_, $_ or 'replace_one' instead.

      so i made a little modification

      my $col = $db->get_collection('counters'); $col->update_one({'_id' => 'comm-id'},{ '$inc' => { 'seq' => 1}}); my $id = $col->find_one({'_id' => 'comm-id'})->{'seq'};

      so now it is working.

      Thanks so much, it really help!

        Hi, sorry for long delay. I solved storing the function using mongo shell, then i had just to call in my procedure.
Re^3: MongoDB Stored procedure from Dancer2
by Corion (Patriarch) on Mar 28, 2017 at 16:16 UTC

    The example seems to send raw Javascript instead of JSON or BSON.

    I don't find any example in the MongoDB documentation that shows how to send raw Javascript.