in reply to Re: How to pass query for mongo DB through perl
in thread How to pass query for mongo DB through perl

I read those twice. Under DATABASE COMMANDS he writes a functions and converted into something. But I dont get idea how to solve that. Please help me with this as a example

  • Comment on Re^2: How to pass query for mongo DB through perl

Replies are listed 'Best First'.
Re^3: How to pass query for mongo DB through perl
by Corion (Patriarch) on Sep 22, 2015 at 06:56 UTC

    With what part of the text do you have problems?

    Next, we can translate the important parts into Perl:

    $db->run_command( [ validate => "foo" ] );

    As this is a project for your studies, I can only recommend talking to your mentor about advice regarding the use of MongoDB.

      Finally I completed like this

      #!/usr/bin/perl use warnings; use strict; use MongoDB; use Time::Local; my $date=$ARGV[0]; $date or $date=`date --date='90 day ago' +%d-%m-%Y`; chomp $date; print "Deleting before this date: ",$date,"\n"; my $db_host="***.**.**.***"; #For security reasons stared my ip my $db_name="ravi"; my $client = MongoDB::MongoClient->new(host => $db_host, port => 2 +7017); my $db = $client->get_database( $db_name ); my $data = $db->get_collection('collection')->find(); while (my $row = $data->next) { my $docDate = $row->{'Date'}; my $queryDate = "14-06-2015"; #substr("okay", 1,2) my $timestamp = ":00:00:00"; $docDate = $docDate.$timestamp; my ($mday,$mon,$year,$hour,$min,$sec) = split(/[\s.:-]+/, $docDate +); my $docDateMillis = timelocal($sec,$min,$hour,$mday,$mon-1,$year); $queryDate = $queryDate.$timestamp; ($mday,$mon,$year,$hour,$min,$sec) = split(/[\s.:-]+/, $queryDate) +; my $queryDateMillis = timelocal($sec,$min,$hour,$mday,$mon-1,$year +); if($docDateMillis < $queryDateMillis) { my $id = $row->{'_id'}; my $removed=$db->get_collection('collection')->remove({'_id' = +> $id}); print $id,":::Removed\n"; } }