Insert data in mongodb using Socket.io
It's because you are passing a string data
, to your insertData
function (judging by your code, I guess you are supposing that data
is actually an object).
Then you are giving data.msg
, which is obviously undefined
, as the first argument of the save
methods, which is expecting you to provide a valid object here.
Please also note that you are using the save
method on a newly created document, instead of using insertOne
.
As you can see in the api documentation, using save
is now deprecated. (I guess you are using the last version which is currently 2.1)