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.