Error to use mongodb filter

0

I'm having an error trying to run a filter on the database.

var params = '{"cd_entidade":"'+ vcd_entidade+'"}';

Movmaterial.find(params).toArray(function(err,docs){
    if (err) throw err;
    console.log(docs);
}

There was an error that I can not solve, it already has two days :( can you help me? I am creating a personal project for studies of the use of mongodb, thanks in advance

    
asked by anonymous 26.06.2018 / 02:09

1 answer

0

Your params is a string, use a normal javascript object.

// aqui nao precisas contatenar como estavas a fazer, isto será suficiente
var params = { cd_entidade: vcd_entidade };

Movmaterial.find(params).toArray(function(err,docs){
    if (err) throw err;
    console.log(docs);
}
    
26.06.2018 / 03:18