简体   繁体   中英

Run MongoDB in Perl

How to convert the following command in perl?

dn.runCommand({group : {
    "ns"      : "stocks",
    "key"     : "date",
    "initial" : {"time" : 0},
    "$reduce" : function(doc, prev) {
        if ( doc.time > prev.time ) {
            prev.time  = doc.time;
            prev.price = doc.price;
            }
        },
    "condition" : {"day" : { "$gt" : "2020/09/30 }}
    }}
)

Regards.

I have not tested the below code, but it maybe works.

use MongoDB;
my $db = MongoDB::Connection->new->test;
$db->run_command({
group => {
    "ns"      => "stocks",
    "key"     => "date",
    "initial" => {"time" => 0},
    '$reduce' => 'function(doc, prev) {
         if ( doc.time > prev.time ) {
            prev.time  = doc.time;
            prev.price = doc.price;
         }
    }',
    "condition" => {"day" => { '$gt' => "2020/09/30" }}
}}
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM