mongodb - Undefined is not a Function-Sails Mongoose -
hi trying write logic in sails using mongoose find , update parameters in mongoose database using serial no in string format.the parameters passing in the body of dhc app(used posting data api). while posting data, getting following error
typeerror: undefined not function @ object.module.exports.createorupdatestatus (/users/febinp/downloads/shubham_application/taqua-parser/api/controllers/status-packetcontroller.js:66:26) @ bound (/usr/local/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21) @ routetargetfnwrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) @ param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) @ pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5) @ nextroute (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:100:7) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:167:11) @ /usr/local/lib/node_modules/sails/lib/router/bind.js:187:7 @ alwaysallow (/usr/local/lib/node_modules/sails/lib/hooks/policies/index.js:207:11) @ routetargetfnwrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) @ param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) @ pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5) @ nextroute (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:100:7) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:167:11) @ /usr/local/lib/node_modules/sails/lib/router/bind.js:187:7 @ clearheaders (/usr/local/lib/node_modules/sails/lib/hooks/cors/index.js:209:3) @ routetargetfnwrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) @ param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) @ pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5) [typeerror: undefined not function] using node inspector found code failing findoneandupdate follows
var msg_parts=params.msg_parts; /*msg_parts.serialno=params.serialno;*/ // adding serial no message parts storing in mongo database var statuspacket=db.statuspacket(msg_parts); //for saving 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 database follows
var schema=new mongoose.schema({ // serial no of device.we require index on column serialno:{ type: string, required:true, index:true }, // battery level take values 0 6(0,1,2,3,4,5,6) batterylevel:{ type:number, min:0, max:6 }, //signal level take values 0 4 (0,1,2,3,4) signallevel:{ type:number, min:0, max:4, }, //charging status=false represents charging off , true represents charging on chargingstatus:{ type:boolean, default:false }, // 7 states of alarm alarminfo:{ type:number }, // false represents gps off , true represents gps on gpsstatus:{ type:boolean }, //default time when new packet arrived createdat: { type: date, default: date.now } }); can me error unable understand going wrong in findoneandupdate?
Comments
Post a Comment