我正在尝试将该脚本中定义的age参数本地更新到mongoDB数据库中,但出现错误“ UnhandledPromiseRejectionWarning:MongoError:无法将$ inc应用于非数字类型的值。{_ id:Objec tId('5c3c5f5142e37c39289b7967')}具有非数字类型字符串的字段“ age”
const {MongoClient, ObjectID} = require('mongodb');
MongoClient.connect('mongodb://localhost:27017/Todoapp', (err, db) =>{
if (err) {
return console.log('Unable to connect to MongoDB server');
}
console.log('Console to MongoDB server');
db.collection('Users').findOneAndUpdate({
_id: new ObjectID('5c3c5f5142e37c39289b7967')
}, {
$set: {
name: 'Anshul',
},
$inc: {
age: 1
}
},{
returnOriginal: false
}).then((result) => {
console.log(result);
});
//db.close();
});