node.js - findOneAndUpdate() 用于两个不同的 ObjectId,但只更新一个
问题描述
我正在构建一个 API,它将跟随者和跟随者推送到用户对象中的两个数组。
我正在尝试使用findOneAndUpdate()
它,但它只更新一个对象中的元素。
let userToFollow = req.body.following;
let userThatfollows = req.body.follower;
Users.findOneAndUpdate(
userToFollow,
{ $push: { followers: userThatfollows } },
{ new: true, upsert: true },
function (err, doc) {
console.log(doc);
}
);
Users.findOneAndUpdate(
userThatfollows,
{ $push: { following: userToFollow } },
{ new: true, upsert: true },
function (err, doc) {
console.log(doc);
}
);
我不确定这是为什么。
解决方案
推荐阅读
- excel - Excel VBA - 删除未合并的行
- javascript - 当用户超过 40 岁时如何返回 true
- python - Pyside-从另一个类添加小部件
- android - 如何确定谁在我的应用中启动了深层链接
- terraform - Terraform 可以在控制台输出中屏蔽变量吗?
- android - 如何获取 Android volley 请求标头?
- c - 读取一个日志文件并以指定格式写入其他文件
- android - 如何在设备尺寸变化时重建 Flutter 小部件,在 Android 应用中 Flutter View 的发布模式下?
- javascript - JS函数在执行后的特定时间内自禁用
- java - 无法创建 android 架构组件 AndroidViewModel 实例。尝试制作一个简单的 Room DB