I cannot solve this problem. Other words updateMany and updateOne cannot work :
router.post('/deleteChat', async (req, res) => {
if(!req.isAuthenticated()) return res.status(400).json({message: "User cant loginned"});
const {currentConversation} = req.body;
try {
await Messages.updateMany({ $and: [ {about: currentConversation._id}, {who_delete: { $nin: [req.user._id] } } ] }, {$push: {who_delete: req.user._id} } )
await Conversation.updateOne( {$and: [ {_id: currentConversation._id}, {status: {$nin: [req.user._id] } } ] }, {$push: {status: req.user._id }} )
return res.json()
} catch (error) {
return res.status(500).json({message: "Something wrong went!"})
}
});
I want to say if user cannot inside array then add insert array. But I cannot do this? What I need use $ne or $nin?