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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |