Answer the question
In order to leave comments, you need to log in
How to send user id?
I set up a chat for the site, created a model for mongo and a function for sending data, but for some reason the user id does not come, although a chat room with its id is created.
Model
const mongoose = require("mongoose");
const ConversationSchema = new mongoose.Schema(
{
members: {
type: Array,
},
},
{ timestamps: true }
);
module.exports = mongoose.model("Conversation", ConversationSchema);
router.post("/", async (req, res) => {
const newConversation = new Conversation({ /* использует модель Conversation*/
members: [req.body.senderId, req.body.receiverId], /*уч. беседы:тело запроса[id.sende,id.rece] */
});
try {
const savedConversation = await newConversation.save();
res.status(200).json(savedConversation);
} catch (err) {
res.status(500).json(err);
}
});
Answer the question
In order to leave comments, you need to log in
Judging by the fact that in the response there are two values in the members field (both null), I can assume that something is still wrong with getting values from body.
Output req.body.senderId, req.body.receiverId and req.body itself to the console
On the screen, it seems that something is wrong with quotes...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question