FieldPath field names may not be empty strings

  Kiến thức lập trình

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

RADON R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT