node.js - how to use populate and aggregate in same statement? -


this 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 result

{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 try not work ... appointments.find({}).populate("patient").aggregate....

in other word, can use populate , aggregate in same statement

any please

with latest version of mongoose (mongoose >= 3.6), can requires second query, , using populate differently. after aggregation, this:

patients.populate(result, {path: "patient"}, callback); 

see more @ mongoose api , mongoose docs.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -