0
我正在嘗試使用郵遞員放入貓鼬數據,但它在服務器控制檯中顯示「TypeError:bear.save不是函數」並導致節點應用程序崩潰。Node.js Mongoose PUT失敗
在這個問題中,我運行兩個應用程序在不同的端口和數據庫具有相同的代碼,正常的http應用程序可以使所有請求(POST,PUT,DEL,GET)成功,但另一個https應用程序無法發出PUT請求,它只能成功發佈POST和GET。
我不明白爲什麼http應用上的相同代碼不顯示錯誤,如果它是代碼問題。請幫幫我。
REST API參考從 - Here
.get(function(req, res) {
Bear.find({ID: req.params.bear_id} , function(err, bear) {
if (err)
res.send(err);
res.jsonp(bear);
});
})
.put(function(req, res) {
Bear.find({ID: req.params.bear_id}, function(err, bear) {
if (err)
res.send(err);
bear.Name = req.body.Name;
//res.json(bear) can send data up to this line
// save the bear (crash after following line)
bear.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Bear updated!' });
});
})
});
錯誤登錄控制檯 -
TypeError: bear.save is not a function
at Promise.<anonymous> (/var/www/vhosts/mydomain.com/nodeapp.js:130:18)
at Promise.<anonymous> (/var/www/vhosts/mydomain.com/node_modules/mpromise/lib/promise.js:162:8)
at emitOne (events.js:96:13)
at Promise.emit (events.js:188:7)
at Promise.emit (/var/www/vhosts/mydomain.com/node_modules/mpromise/lib/promise.js:79:38)
at Promise.fulfill (/var/www/vhosts/mydomain.com/node_modules/mpromise/lib/promise.js:92:20)
at /var/www/vhosts/mydomain.com/node_modules/mongoose/lib/query.js:1736:26
at model.Document.init (/var/www/vhosts/mydomain.com/node_modules/mongoose/lib/document.js:251:11)
at completeMany (/var/www/vhosts/mydomain.com/node_modules/mongoose/lib/query.js:1734:12)
at cb (/var/www/vhosts/mydomain.com/node_modules/mongoose/lib/query.js:1697:11)
我是一個節點初學者。謝謝你的額外3個字;)。現在工作很完美。 –