How can I get data other than 24 Hours in Mongoose

Issue

  var allData = await Account.find({})
  var hoursData = await Account.find({"_time":{ $gt:new Date(Date.now() - 24*60*60 * 1000) }})


  var AllData_array = [];
  allData.forEach(data => {
    var _WalletAdress = data._WalletAdress;
    AllData_array.push(_WalletAdress)
});

var HoursData_array = [];
hoursData.forEach(data => {
  var _WalletAdress = data._WalletAdress;
  HoursData_array.push(_WalletAdress)
});


var test = AllData_array.filter(x => !HoursData_array.includes(x));

I need to fetch any data that is not updated within 24 hours..I made an example like above but this query is running very slow.My Schema is like this;

_ts:{type:String,default:Date.now()}

Solution

This might help

Account.find({ 
   "_time" : { 
      $lte: new Date(new Date().setDate(new Date().getDate()-1))
   }   
})

Answered By – Anveeg Sinha

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.