javascript - TypeError:更新文档需要原子操作符
问题描述
错误详情:
TypeError: Update document requires atomic operators
at new UpdateOneOperation (C:\Users\niko\Desktop\My Workspace\node_modules\mongodb\lib\operations\update_one.js:14:13)
at Collection.updateOne (C:\Users\niko\Desktop\My Workspace\node_modules\mongodb\lib\collection.js:772:5)
at exports.insert (C:\Users\niko\Desktop\My Workspace\controllers\controller.js:16:47)
at Layer.handle [as handle_request] (C:\Users\niko\Desktop\My Workspace\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\niko\Desktop\My Workspace\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\niko\Desktop\My Workspace\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\niko\Desktop\My Workspace\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\niko\Desktop\My Workspace\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\niko\Desktop\My Workspace\node_modules\express\lib\router\index.js:335:12) at next (C:\Users\niko\Desktop\My Workspace\node_modules\express\lib\router\index.js:275:10)
const {getDb} = require('../config/db-steup')
exports.insert = (async (req,res) => {
const object = {
financial: {
salary: {
amount: req.body.financial.salary.amount,
type: req.body.financial.salary.type,
}
}
}
const name = req.body.name;
try{
await getDb().db().collection('post').updateOne({$push:{ posts: object}}, {name:name});
return res.json({message: "Sucessfully Updated DB"})
}
catch (err){
console.log(err)
}
});
exports.delete = (async (req, res, next) => {
var {email} = req.query;
console.log(email);
const emailExist = await getDb().db().collection('test').findOne({email});
if (emailExist) {
await getDb().db().collection('test').deleteOne({email})
return res.json({message: "User Successfully deleted"})
}else{
return res.json({message: "email doesnt exist"})
}
});
解决方案
推荐阅读
- terraform - 在 terraform 上获取数据
- python - 如何在python中输入多个值?
- python - 用户输入被拒绝并再次请求(其他解决方案不起作用)
- javascript - axios 返回一个 promise 对象
- javascript - 错误 [ERR_HTTP_HEADERS_SENT]:在 NodeJs 中将标头发送到客户端后无法设置标头
- django - Django 离线文档语言
- php - javaldx 失败!警告:无法从 javaldx 读取路径(在使用 php 的 docker 容器中)
- cluster-analysis - 关于修改TDengine的replica值?
- entity-framework - EF Core 过滤包含与选择
- laravel - 为什么在 Laravel 8 中的 hasValidSignature 上,signedRoute 总是错误的。*