내 말은 스택 백엔드를 구축하고,하지만 난 DB에 문서를 업데이트 할 때 오류가 점점 오전 :MongoDb를 업데이트 할 때 오류가 발생하는 이유는 무엇입니까?
topUp = function(name, amount, callback) {
User.updateOne(
{ "name" : name },
{ $set: { "wallet": amount } },
function(err, results) {
console.log(results);
callback();
});
};
형식 오류 : User.updateOne는 함수가 아닙니다
그러나 예를 들어, findOne()은 정상적으로 작동합니다.
User.findOne({
name: decoded.name
}, function(err, user) {
if (err) throw err;
i
f (!user) {
return res.status(403).send({success: false, msg: 'Authentication failed. User not found.'});
} else {
//res.json({success: true, info: {wallet: user.wallet, userPic: user.userPic}});
topUp(decoded.name, amount, function() {
User.close();
});
}
});
"사용자"는 Mongo 모델 파일입니다.
'findOne'은 미리 정의 된 함수이기 때문에'updateOne()'은 미리 정의 된 함수가 아니기 때문에. 기본적으로 하나의 레코드 만 업데이트해야합니다. 다중 레코드를 업데이트하려면'multi : true'를 사용할 수 있습니다. –
@MohitBhardwaj 음, Mongo 문서에 따르면 updateOne()도 미리 정의되어 있습니다. [proof] (https://docs.mongodb.com/getting-started/node/update/) – boooni
데이터베이스 드라이버에는 정의되어 있지 않습니다. 당신이 사용하고 있을지도 모릅니다. Mongoose를 사용하고 있는데'updateOne()'을 사용할 수 없다고 생각합니다. 모든 드라이버에서 모든 기본 mongodb 기능을 사용할 수는 없습니다. –