Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


how to use populate and aggregate in same statement


how to use populate and aggregate in same statement  using -'node.js,mongodb,mongoose'

this is my appointment collection

{ _id: ObjectId("518ee0bc9be1909012000002"), date: ISODate("2013-05-13T22:00:00Z"), patient:ObjectId("518ee0bc9be1909012000002") }

{ _id: ObjectId("518ee0bc9be1909012000002"), date: ISODate("2013-05-13T22:00:00Z"), patient:ObjectId("518ee0bc9be1909012000002") }

{ _id: ObjectId("518ee0bc9be1909012000002"), date: ISODate("2013-05-13T22:00:00Z"), patient:ObjectId("518ee0bc9be1909012000002") }


i use aggregate to get result like this

{date: ISODate("2013-05-13T22:00:00Z"),
patients:[ObjectId("518ee0bc9be1909012000002"),ObjectId("518ee0bc9be1909012000002"),ObjectId("518ee0bc9be1909012000002")] }


like this

Appointments.aggregate([
{$group: {_id: '$date', patients: {$push: '$patient'}}},
{$project: {date: '$_id', patients: 1, _id: 0}}
], ...)


how can populate patient document
i try this but not work ... Appointments.find({}).populate("patient").aggregate....

in other word can use populate and aggregate in same statement

any help please
    

asked Sep 29, 2015 by gauravsinghal83
0 votes
191 views



Related Hot Questions



Government Jobs Opening


...