Я храню данные в mongodb в следующем формате:
_id: 5d2575fed2fe8a1fd660abb7
id: 1
projectName: "aaa"
versionProject: "1"
startTime: "10/07/2019, 10:52:04"
startToIBM: "00:00:04"
ibmToSequence: "00:00:02"
sequenceToMapping: null
mappingTofininsh: null
endTime: null
totalTime: null
mappingData:
Array
0
:
Object:1
id: 1
sourceFileName: "https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl"
targetFileName: null
sourceTargetName: "Source: https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.ph..."
sourceName: null
sfieldName: null
sdataType: null
targetName: "NDFDgen"
tfieldName: "latitude"
tdataType: "xsd:decimal"
urgencyName: "Optional"
descriptionName: null
directRowNo: null
sourceFieldPath: null
sourceFieldName: null
datatypeVerified: null
backgroundColor: "true"
Object:1
Я хочу обновить descriptionName mappingData для определенного идентификатора, но не могу понять, как обновить это, когда я получаю Не могу прочитать свойство 'update' неопределенной ошибки, ниже мой код:
function updateDescriptionData(req, res) {
console.log("data inside update ====.", req.body);
var inputId = parseInt(req.body.id)
// var newDirectRowNo=parseInt(req.body.update.directRowNo);
// var newSourceFieldPath=(req.body.update.sourceFieldPath).toString();
// var newSourceFieldName = (req.body.update.sourceFieldName).toString();
// var newDatatypeVerified=(req.body.update.datatypeVerified).toString();
// var newValue={$set :{directRowNo:newDirectRowNo,sourceFieldPath:newSourceFieldPath,sourceFieldName: newSourceFieldName,datatypeVerified:newDatatypeVerified}}
var newDescription = (req.body.descriptionName).toString();
console.log("inside input id field of update===", inputId);
// console.log("inside input id field of update===",newDirectRowNo);
console.log("inside input id field of update===", newDescription);
// console.log("inside input id field of update===",newSourceFieldName);
// console.log("inside input id field of update===",newDatatypeVerified);
var dataUpdate =
req.body;
var deferred = Q.defer();
db.projectManagement.update({
"mappingData.id": inputId
}, {
$set: {
"mappingData.$": dataUpdate
}
}, function (err, doc) {
if (err) {
deferred.reject(err.name + ': ' + err.message);
}
deferred.resolve({
message: "success"
});
});
db.close();
return deferred.promise;
}
Я получаю сообщение об ошибке:
TypeError: Невозможно прочитать свойство 'update' из неопределенного
но я хочу, чтобы он обновился.