Search by date model find mongoose not working

-1

I am trying to find x objects by date, (the receipt of a form, I know it arrives in UTC format before the real one), I do the following.

First I create the object

console.log(datos) // Contiene los datos correctos , fecha ,datos ,etc

Evento.create(datos,(err,evento)=>{
    if(err)console.log("Error");
    else{
        console.log("Eventro creado",evento);
                        Task.create({
                            fecha:datos.fecha,
              cron: {
                enabled: true,
                startAt: datos.fecha,
                interval: '40 * * * * *' 
              }
            });


        User.update({_id:datos.creador},{$push:{eventos:evento._id}},{},(err,user)=>{
            if(err)console.log(err);
            else{
                console.log("Usuario actualizado");
                console.log(user);
            }
        });
    }
});

I check in the bd, and in fact, I believe that event with the corresponding date, but then there below I try to search for

console.log("Buscaremos el evento x por fecha");
Evento.find({fecha:datos.fecha},(err,ev)=>{
    console.log("Estos son los eventos encontrados",ev);
})

and I get ev = [], having an event that matches the given date, and review and the dates are the same, what could be happening?

    
asked by Kevin AB 19.10.2016 в 15:16
source

1 answer

0

Well I found the solution, I see that it was because when I created the model in mongo, it stores the date in ISO format, so you only had to use data. date.toISOString (), to compare the dates.

    
answered by 19.10.2016 в 15:35