I need to look for a record in mongoDb by the NUMERO_RUC using node.js, try for findById and it works perfectly but I want to search for other data that is not the id, you can help me I do not know where my fault is.
Method to obtain a record:
//Obtener registros con el ruc
app.get('/personas/:ruc', function(req, res) {
rucs.findById(req.params.ruc, function(error, persona) {
if (error) return res.status(500).send(error);
res.json(persona);
});
});
This is the record in MongoDB:
{
"_id": "5b82eaac31e4182794de57d3",
"NUMERO_RUC": "1703467785001",
"RAZON_SOCIAL": "BASANTES JARA MARIANA DE JESUS",
"NOMBRE_COMERCIAL": "",
"ESTADO_CONTRIBUYENTE": "ACTIVO",
}
I'm doing tests with Postman and I get the following error when I want to get the record through the ruc:
"message": "Cast to ObjectId failed for value \"1703467785001\" at path
\"_id\" for model \"rucs\"",
"name": "CastError",
"stringValue": "\"1703467785001\"",
"kind": "ObjectId",
"value": "1703467785001",
"path": "_id"
}