Search with array in mongodb with nodejs

0

I am creating a restFull api with nodejs and mongodb. I'm trying to do a query on mongodb and nodejs, but I do not get the form. I have the problem in looking over the array that arrives by parameter, I try to make the $ in on the array and it gets stuck.

exports.getAlertasDistritoCategoria = (distrito, categorias) =>

new Promise((resolve, reject) => {

    alerta.find({distrito: distrito, categoria:{$in:categorias}}).sort({fecha:-1})
    .then(alertas => categorias)

    .catch(err => reject({status: 500, message: 'Internal Server Error! verAlertasDistritoCategoria.js'}))


});
    
asked by Miriam Panero 21.04.2018 в 13:47
source

1 answer

0

The query looks good, but in .then(alertas => categorias) the resolve would be missing. Ex:

exports.getAlertasDistritoCategoria = (distrito, categorias) => (
    new Promise((resolve, reject) => {

        alerta
            .find({distrito: distrito, categoria:{$in:categorias}}).sort({fecha:-1})
            .then((alertas) => {
                resolve(alertas); // o tambien resolve(categorias) si deseas retornar categorias
            })
            .catch(err => reject({status: 500, message: 'Internal Server Error! verAlertasDistritoCategoria.js'}))
    })  
)
    
answered by 23.04.2018 / 19:58
source