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


In reply to 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.