I'm trying to make an insertion in MongoDB by passing some arguments in JSON:
{
"name": "TESTE",
"category": "B",
"service": "Novo processo",
"description": "Novo Teste",
"active": false,
"classmodels": [
{"id": "5bbe37ef8eb26d0025624fcd", "amount": 10},
{"id": "5bbe37ef8eb26d0025624fcd", "amount": 14}
]
}
You are returning the following error:
Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
It is also returning the status code as 500 (Internal Server Error), but I am able to use other endpoints with no problem at all.
The functions in NodeJS that I'm using are these:
First to be called.
addStandardClassTemplate: function(req, res) {
let name = req.body.name;
let category = req.body.category;
let service = req.body.service;
let description = req.body.description;
let active = req.body.active;
let classmodels = req.body.classmodels;
console.log('Entrou no método de Adicionar Template de Aula Padrão');
classtemplatesMethods.add.addStandard(name, category, service, description, active, classmodels)
.then((result) => {
res.status(200).send(result);
})
.catch((error) => {
res.status(404).send(error);
});
},
Second to be called.
addStandard: function(name, category, service, description, active, classmodels) {
classmodels.forEach((item, index) => classmodels[index] = ObjectId(item));
let NewValues = {
name: name,
category: category,
service: service,
description: description,
active: active,
classmodels: classmodels,
};
console.log('QUERY Adicionar Template de Aula Padrão');
return new Promise((resolve, reject) => {
mongoMethods.add.insert(targetcollection, NewValues)
.then((result) => resolve(result))
.catch((error) => reject(error));
});
},