ravi45722 has asked for the wisdom of the Perl Monks concerning the following question:

In my DB the data is like this.

> db.collection.find(); { "_id" : ObjectId("55ffec992363a42957aebea8"), "Date" : "14-11-2014", + "Value" : 25.36 } { "_id" : ObjectId("55ffeca02363a42957aebea9"), "Date" : "14-12-2014", + "Value" : 25.36 } { "_id" : ObjectId("55ffeca72363a42957aebeaa"), "Date" : "14-01-2015", + "Value" : 25.36 } { "_id" : ObjectId("55ffecac2363a42957aebeab"), "Date" : "14-02-2015", + "Value" : 25.36 } { "_id" : ObjectId("55ffecb12363a42957aebeac"), "Date" : "14-03-2015", + "Value" : 25.36 } { "_id" : ObjectId("55ffecb52363a42957aebead"), "Date" : "14-04-2015", + "Value" : 25.36 } { "_id" : ObjectId("55ffecb92363a42957aebeae"), "Date" : "14-05-2015", + "Value" : 25.36 } { "_id" : ObjectId("55ffecc02363a42957aebeaf"), "Date" : "14-06-2015", + "Value" : 25.36 } { "_id" : ObjectId("55ffecc42363a42957aebeb0"), "Date" : "14-07-2015", + "Value" : 25.36 } { "_id" : ObjectId("55ffecc82363a42957aebeb1"), "Date" : "14-08-2015", + "Value" : 25.36 }

In this I want to delete old data. For that I have this query (Tested)

var cursor = db.collection.find() while (cursor.hasNext()) { var doc = cursor.next(); var docDate = doc.Date; var queryDate = "14-03-2015"; var docDateMillis = new Date(docDate.substring(6,10), docDate.substri +ng(3,5)-1, docDate.substring(0,2)).getTime(); var queryDateMillis = new Date(queryDate.substring(6,10), queryDate.s +ubstring(3,5)-1, queryDate.substring(0,2)).getTime() if(docDateMillis < queryDateMillis) { db.collection.remove({_id : doc._id}) } }

How can I pass this query to my database through perl

Replies are listed 'Best First'.
Re: How to pass query for mongo DB through perl
by Corion (Patriarch) on Sep 21, 2015 at 12:32 UTC

    Maybe now is a good time to read the documentation?

    I already showed you MongoDB::Examples. Maybe you can find a way to run predefined code in the examples?

      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

        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.