I try to send a message but i receive a mongodb error
FieldPath field names may not be empty strings.
Here’s code
const {message} = req.bod;
const {id:receiverId} = req.params.id;
const senderId = req.user._id
let converstation = await Converstation.findOne({
participants: { $all: [senderId, receiverId]}
})
if(!converstation) {
converstation = await Converstation.create({
participants: [senderId, receiverId],
})
}
const newMessage = new Message({
senderId,
receiverId,
message,
})
if(newMessage) {
converstation.messages.push(newMessage._id)
}
await converstation.save()
await newMessage.save()
res.status(201).json(newMessage)
What should I do?
I already tried to change code, but nothing works
New contributor