我有一个 mongo 集合。使用 node.js 驱动程序:
db.collection('notify').find();
回报:
{ _id: '1376179201714-user102',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'Training is past due!',
message: 'Training3 is past due!!!',
recipient: [ 'test@test.com' ] }
{ _id: '1376179201714-user103',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'training is past due!',
message: 'Training2 is past due!!!',
recipient: [ 'test@test.com' ] }
{ _id: '1376179201714-user104',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'training is past due!',
message: 'Training5 is past due!!!',
recipient: [ 'test@test.com' ] }
{ _id: '1376179201714-user133',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'training is past due!',
message: 'Training1 is past due!!!',
recipient: [ 'test2@test.com' ] }
{ _id: '1376179201714-user134',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'training is past due!',
message: 'Training2 is past due!!!',
recipient: [ 'test2@test.com' ] }
{ _id: '1376179201714-user135',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'training is past due!',
message: 'Training4 is past due!!!',
recipient: [ 'test2@test.com' ] }
{ _id: '1376179201714-user203',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'training is past due!',
message: 'Training1 is past due!!!',
recipient: [ 'test3@test.com' ] }
{ _id: '1376179201714-user204',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'Training2 is past due!',
message: 'Card maker, updating member info is past due!!!',
recipient: [ 'test3@test.com' ] }
{ _id: '1376179201714-user205',
state: 'unread',
sender: 'Daily Notify Process',
datereceived: 1376179201714,
subject: 'training is past due!',
message: 'Training3 is past due!!!',
recipient: [ 'test3@test.com' ] }
我可以使用 mapreduce 或 group 让它看起来像这样吗:
{recipient: ['test@test.com'],
subject: 'Training is past due!',
trainingblock: [
{message: 'Training3 is past due!!!'},
{message: 'Training2 is past due!!!'},
{message: 'Training5 is past due!!!'}
]
}
{recipient: ['test@test.com'],
subject: 'Training is past due!',
trainingblock: [
{message: 'Training1 is past due!!!'},
{message: 'Training2 is past due!!!'},
{message: 'Training4 is past due!!!'}
]
}
{recipient: ['test@test.com'],
subject: 'Training is past due!',
trainingblock: [
{message: 'Training1 is past due!!!'},
{message: 'Training2 is past due!!!'},
{message: 'Training3 is past due!!!'}
]
}
或者我需要在 javascript/node 端做吗?