Thursday, 16 March 2017

How do you sort this in underscore node js monogodb?

I know I should have researched this but I am on a strict time schedule. How do make the following string:

[ { _id: { eventName: 'sometsdf', confirmed: false }, total: 1 },
  { _id: { eventName: 'somethon', confirmed: true }, total: 1 },
  { _id: { eventName: 'somethon', confirmed: false }, total: 1 } ]

into something like

[ { eventName: 'somethon, confirmed: 1 , unconfirmed: 1},
  { eventName: 'sometdsf, confirmed: 0 , unconfirmed: 1}, ]

I have used aggregate function from mongodb as following

obj.aggregate[{
$group: {
    _id: {eventName: "$eventObject.event_name", confirmed: "$confirmation"},
    total: {$sum: 1}
}
}]

It has been only 8 hours since I have learned about node js and this is an emergency since the back end developer left. Please help.



via hraw

No comments:

Post a Comment