I have a socket.io based chat server that saves messages to MongoDB. When a user sends something like ಠ_ಠ it is emitted through the socket and displayed correctly, but when I take that same message and save it to MongoDB through Mongoose I end up with ಠ_ಠsaved in the database.
I thought Mongoose/MongoDB/socket.io all spoke UTF-8 by default...why is the data being converted to ASCII when I save it to the DB?
socket.on('newMessage', function(data){
var data = JSON.parse(data);
var chatMessage = new ChatMessage();
chatMessage.user = data.userId;
chatMessage.room = data.roomId;
chatMessage.message = data.message.toString("utf8");
chatMessage.save(function(err, message){
// Emits ಠ_ಠ
socket.broadcast.to(data.roomId).emit('deliverMessage', JSON.stringify(message));
});
I'm even emitting what was saved to MongoDB (message not data.message), but MongoDB has ಠ_ಠstored....SOOOOOO confused :s
I understand encoding and why it matters. My question is which part of the socket.io, mongoDB, mongoose pipeline is switching the encoding and why when everything seems to be speaking uft-8?