1

I have a Mongoose query for a Mongo instance where I have a DB which contains a bunch of records where I want to get all documents where the 'stripe.trialEnd' is older than the current time but where the 'stripe.isPaid' value is false. I wrote this query and it seems to select fine based on the isPaid value but will always pick up a value for the cutoff. I am looking for how I can get this query to work correctly.

let cutoff = new Date();
Company.find({'stripe.trialEnd': {$lt: cutoff}, 'stripe.isPaid': { '$in': ['false', false]} })

Example DB document

{
_id: <123abc>
   stripe: {
      isPaid: false,
      trialEnd: 1608943761 // Epoch time
   }
...
}

A similar post that I modeled my query after: Querying with mongoose and dates

joshk132
  • 1,011
  • 12
  • 37

1 Answers1

0

I think I solved the issue, so mongoose isn't converting the date to epoch time and therefore the compare is returning false all the time and giving me results. I changed how I create the date to give me epoch time seen below, that seems to have resolved the issue.

let cutoff = Date.now();
joshk132
  • 1,011
  • 12
  • 37