【发布时间】:2016-04-06 22:54:30
【问题描述】:
嗨,我正在尝试从 mongoDB 中删除一个值,但代码不是删除特定值,而是从架构中删除所有用户,哈哈。
var mongoose = require('mongoose');
var User = require('../../models/UserModel');
module.exports.unfollow = function(req, res){
var thefollowee = req.body.followee;
var thefollower = req.body.follower;
User.find({_id: thefollower}).remove({following: thefollowee}).exec();
User.find({_id: thefollowee}).remove({followers: thefollower}).exec();
res.json({ message: 'Unfollowed'});
};
followee 指向被关注者的 id, follower指向的是关注followee的用户的id。
【问题讨论】:
-
我刚刚看到你的答案弹出来了,不过你也可以使用猫鼬的findOneAndRemove 方法。
标签: mongodb express mongoose stack mean