您好我正在尝试使用Mongoose在Sails中编写一个逻辑,以使用串行编号以字符串格式查找和更新Mongoose数据库中的参数。我传递的参数位于DHC应用程序的正文中(用于将数据发布到API)。在发布数据时,我收到以下错误
TypeError: undefined is not a function
at Object.module.exports.createORupdateStatus (/Users/febinp/Downloads/Shubham_application/taqua-parser/api/controllers/Status-packetController.js:66:26)
at bound (/usr/local/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
at routeTargetFnWrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5)
at callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5)
at nextRoute (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:100:7)
at callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:167:11)
at /usr/local/lib/node_modules/sails/lib/router/bind.js:187:7
at alwaysAllow (/usr/local/lib/node_modules/sails/lib/hooks/policies/index.js:207:11)
at routeTargetFnWrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5)
at callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5)
at nextRoute (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:100:7)
at callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:167:11)
at /usr/local/lib/node_modules/sails/lib/router/bind.js:187:7
at clearHeaders (/usr/local/lib/node_modules/sails/lib/hooks/cors/index.js:209:3)
at routeTargetFnWrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5)
at callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5) [TypeError: undefined is not a function]
使用Node Inspector我发现我的FindOneAndUpdate代码失败,如下所示
var msg_parts=params.msg_parts;
/*msg_parts.SerialNo=params.SerialNo;*/ // Adding the Serial no into the message parts for storing in the mongo Database
var statuspacket=db.StatusPacket(msg_parts);
//For saving into the Database
statuspacket.findOneAndUpdate({"SerialNo":SerialNo1},msg_parts,function(err,data){
if (err) {
res.json({
success: false,
exception: err
});
return;
}else{
statuspacket.save(function(err,data){
if(err){
res.json({
success: false,
exception: err
});
return;
}else{
res.json({
success: true,
data:data
});
return;
}
});
}
});
数据库的MY Schema如下
var schema=new mongoose.Schema({
// Serial No of the device.We require an Index on this column
SerialNo:{
type: String,
required:true,
index:true
},
// battery level will take values from 0 to 6(0,1,2,3,4,5,6)
batteryLevel:{
type:Number,
min:0,
max:6
},
//Signal Level will take values from 0 to 4 (0,1,2,3,4)
signalLevel:{
type:Number,
min:0,
max:4,
},
//Charging status=false represents Charging OFF And true represents charging on
chargingStatus:{
type:Boolean,
default:false
},
// 7 states of the alarm
alarmInfo:{
type:Number
},
// false represents GPS OFF And true represents GPS on
gpsStatus:{
type:Boolean
},
//Default time when the new packet arrived
createdAt: {
type: Date,
default: Date.now
}
});
有人可以帮助我解决错误,因为我无法理解我在FindOneAndUpdate错误的位置吗?