0

How can I use below script for deleting 5K records:

db.transaction.deleteMany({
  "timeStamp": { $gte: new Date(2018, 0, 1), $lt: new Date(2019, 0, 1) }
})

I tried with finding first in collection, but it's saying 0 records fetched.

db.transaction.find({
  "timeStamp": { $gte: new Date(2018, 0, 1), $lt: new Date(2019, 0, 1) }
})

Output: Fetched 0 record(s) in 31ms

But i checked in collection below records with these timestamp are present,

"timeStamp" : ISODate("2018-12-31T18:30:03.379Z"),

"timeStamp" : ISODate("2018-12-31T18:30:03.982Z"),

Nimantha
  • 6,405
  • 6
  • 28
  • 69
prat_86
  • 91
  • 2
  • 10
  • doesn't it work as-is? – Sergio Tulentsev Jul 13 '20 at 19:37
  • 1
    Does this answer your question? [Mongoid delete many with limit](https://stackoverflow.com/questions/51917027/mongoid-delete-many-with-limit) – Shreeram K Jul 13 '20 at 21:47
  • You code above looks good on my local machine. What is the type of `timeStamp` in your collection? One problem I met before was my existing data in the collection was `Date` type while my client side uses `String` type for newly inserted data, which causes unexpected behavior when sorting by that field. – fishstick Jul 14 '20 at 01:03
  • Having more then 10 Lakh records in collection, so need to delete 5K records to overcome load on DB...how to use above script for tht. – prat_86 Jul 14 '20 at 05:56
  • Hi Experts,I need to delete 5K records from the above script, how can i use it: db.transaction.deleteMany({ "timeStamp": { $gte: new Date(2018, 0, 1), $lt: new Date(2019, 0, 1) } }) :- in my collection it's timestamp only with field. – prat_86 Jul 14 '20 at 11:04

0 Answers0