
처음에 방을 생성 하고 사용자를 배열로 넣어두고

컬렉션 안에서 하나 하나 씩 추가되는 방식이 맞는걸까요 ..?
room 아이디를 넣어줘서 상관은 없나 ? 싶기도하고
socket.on("message-send", async (data) => {
// 브로드 캐스트라는 채팅방에 메세지를 보내줌
const room = data.room;
const msg = data.msg;
const userId = socket.id;
let result = await db
.collection("chatroomIn")
.insertMany([
{
roomId: new ObjectId(room),
userId: userId,
msg: msg,
date: new Date(),
},
]);
console.log("채팅방", result);
io.to(data.room).emit("message-broadcast", {
msg: data,
userId: socket.id,
});
메세지를 보낼때 저장하고 보내는 식으로 했습니다