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

204
Views
Mongoose: Sorting is not working as expected

I'm facing a strang problem while sorting documents in mongoose.

I have a huge scheme named as Property that contain a price object something like this:

{
    info: {
        price: {
            price: 361000 // number
        }
    }
}

Property Model:

@Field(() => Number, { nullable: true })
@Prop({ type: SchemaTypes.Number })
price: number;

Now, I have to sort the properties via property price i.e info.price.price.

What I have done:

const properties = await this.propertiesModel
  .find({})
  .skip(skipBy)
  .limit(size)
  .sort({ "info.price.price": -1 }); // sorting

The results are not as expected:

{
    "info": {
    "price": {
        "price": 999000
    }
    }
},
{
    "info": {
    "price": {
        "price": 99900 // wrong 
    }
    }
},
{
    "info": {
    "price": {
        "price": 997000
    }
    }
}

The schema is already using the Number type for price but seems like it's sorting as a string somehow.

about 4 years ago · Juan Pablo Isaza
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!