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"; } }

In reply to Re^4: How to pass query for mongo DB through perl by ravi45722
in thread How to pass query for mongo DB through perl by ravi45722

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.