简体   繁体   English

在Perl中运行MongoDB

[英]Run MongoDB in Perl

How to convert the following command in perl? 如何在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" }}
}}
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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