Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
Mongodb $min value is greater than $max sometimes

I'm fetching date from mongo database and returns $first,$max, $min, and $last, however something very unusual happens - $min is greater than $max. Here's my code:

let Lowestdate = await ETHMongo.aggregate([
  {
    $match: { createdAt: { $gte: new Date(last), $lte: new Date(NEW) } },
  },    
  {
    $group: {
      _id: null,

      minFee_doc: { $first: "$$ROOT" },
      minFee: { $min: "$one" },

      firstFee: { $first: "$one" },
      lastFee: { $last: "$one" },
      maxFee: { $max: "$one" },
    },
  },
]).then((result) => {});

Any solution? Table Heading Wrong results

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It looks like your "numbers" are saved as string, in string comparison "99" > "1000000".

Luckily you can solve this very easily, just cast the string to number using $toInt

{
    $group: {
        _id: null,

        minFee_doc: { $first: "$$ROOT" },
        minFee: { $min: {$toInt: "$one"} },

        firstFee: { $first: "$one" },
        lastFee: { $last: "$one" },
        maxFee: { $max: {$toInt: "$one"} },
    },
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!