Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
sort mongodb data based on array express react

i have record in mongoose which kinda look like this(demo) -

{
    name:"son",
    email:"final@gmail.com",
    score:[40,100,30,5]
}

my model is -

const uModel =  new Schema({
name: {
    type: String,
    required: true,
    max: 20, 
},
email: {
    type: String,
    required: true,
    unique: true,
    max: 50,
    min: 6
},
password: {
    type: String,
    required: true,
    min: 6
},
profile:{
    type: String,
    default: ''
},
score:{
    type: Array
}})

and here is my post method in express -

const getAllData = (req, res)=>{
userModel.find().sort({score: -1})
.then(user =>{
    res.status(200).json(user)

})
.catch(err=>{
    res.status(200).json(err)
})}

i have a dashboard and i want to show user with highest score(score is dynamic, changes all the time) what i want is to sort score array(descending order ) and then sort user based on highest score(descending order). two thing what i want but i have no idea how to do it. after sorting 0 index of score array should have the higher value and last index lowest.

find().sort({}) does not work for me.

is it possible or should i change my strategy if i should change then what could be better one ?? thanks in advance

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda