通过mongoose更改json输出的格式

时间:2018-09-12 11:42:42

标签: mongoose merge field

我在猫鼬中有一个包含数组的数据。

结果在下面

...
var webSocketServer = new WebSocketServer.Server({ port: 8081 });
...
/*
 * method: broadcast
 * @data: the data you wanna send
 * @sender: which client/ws/socket is sending
 */
webSocketServer.broadcast = function(data, sender) {
  webSocketServer.clients.forEach(function(client) {
    if (client !== sender) {
      client.send(data)
    }
  })
}

...
// On your message callback.
ws.on('message', function(message) {
 ...
  // Note that we're passing the (ws) here
  webSocketServer.broadcast(message, ws);
})

我想合并所有内容(如果可能,在猫鼬中),这样看起来像这样

[{ first_name: 'Micheal', last_name: 'Smith'},  _id: 5b9896d308925c0f5cd866ff,  team:    [ { name: 'swift', color: 'yellow'} ] ,     
{ first_name: 'Evelyn',last_name: 'Nestor'},  _id: 5b9897ea08925c0f5cd86740,  team:    [ { name: 'amethyst', color: 'pink'} ] ,     
{ first_name: 'Favour',last_name: 'Polish'},  _id: 5b98987f08925c0f5cd86780,  team:    [ { name: 'laser', color: 'green'} ] ,     
{ first_name: 'Winney',last_name: 'Marek'},  _id: 5b98991508925c0f5cd867c0,  team:    [ { name: 'jade', color: 'blue'} ] }]

0 个答案:

没有答案