Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: How to pass query for mongo DB through perl

by Corion (Patriarch)
on Sep 22, 2015 at 06:56 UTC ( [id://1142703]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^4: How to pass query for mongo DB through perl
by ravi45722 (Pilgrim) on Sep 23, 2015 at 03:43 UTC

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1142703]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found