-1
I have an appointment at Nodejs with Mongodb:
filter:['abertos','cancelados'];
schemas.chamados
.find({STATUS_CHAMADO : {"$in" : filter}})
.exec(function(err, dados) {
if(err) return callback(err);
else {
return callback(dados);
}
});
Displays the following error:
Object {message: "Cast to string failed for value "undefined" at path "STATUS_CHAMADO"", name: "CastError", type: "string", path: "STATUS_CHAMADO"}
Does anyone know what it can be ?
When the user selects the filter on the angular front end, the Node will search for these values.
This filter comes from a checkbox passed by the angular, If it comes like this: ["open", null, null], the error happens now if it comes ["open", "canceled", "finished"] will normally.
– Guilherme De Menezes Ferreira
Yes is constant, even using a string does not work! So of the error if the filter variable comes from the angle, if I set it manually works.
– Guilherme De Menezes Ferreira
The same mistake happens !!
– Guilherme De Menezes Ferreira
even if it is
{'status_chamado' : { '$in': filter}}appears"Cast to string failed for value "status_chamado" at path "status_chamado""Then you wouldn’t need to cast if it’s already string– Caputo
Yes, even then the error appears, but only when the filter is variable. If I set var filter=['open','cleared','finished'] not from the error.
– Guilherme De Menezes Ferreira
(I removed the previous comments) Maybe this filter isn’t coming as an array, try to validate by putting something like
console.log(typeof filter)– Caputo
Testei, returns as Object array
– Guilherme De Menezes Ferreira
I’ve tried everything to my knowledge, someone has some idea that it might be happening ?
– Guilherme De Menezes Ferreira
So that’s it. It should be an array. Convert to array that will solve
– Caputo
Caputo, solved. You were right ! Thank you very much.
– Guilherme De Menezes Ferreira