title: How to emit object using socket.io?
body: <p>I have a code like, I have a problem with sending response. </p>
  
  <pre><code>socket.on('findUserMessages', (userName) =&gt; {
      io.sockets.connected[socket.id].emit('Checking-message', {
          type: 'ss',
          text: bot,
          user: 'bot'
      });
  
      var dupa = db.chat.find({ user: userName }, function(err, docs) {
          userName = userName
          if (err) throw err;
          console.log('load old messages', docs)
      })
  
      io.emit('private message', dupa);
  })
  </code></pre>
  
  <p>My node console output is like </p>
  
  <pre><code>[ { _id: 5888bdd6cef7952e38821f35,
  text: 'O rajciu rajciu',
  user: 'Adam',
  time: 2017-01-25T15:01:42.733Z }]
  </code></pre>
  
  <p>I know that output is not a JSON string, how to solve that? I was trying to use .toArray() but without succes.</p>
  
  <p>That might be silly question but I am stuck with it for a long time. </p>