Skip to content

Instantly share code, notes, and snippets.

Last active January 4, 2016 04:49
What would you like to do?
// .lean()
.populate('contacts.person', 'id email avatar name nestedModel')
// FIXME feels like we should be able to get nested populations instead
// on building them inside the promise.
// .populate('contacts.person.nestedModel')
.then(function (doc) {
NestedModel.populate(doc.contacts, {
path: 'person.nestedModel',
// FIXME this is still returning expired Flares.
options: {
sort: {updatedAt: -1},
}, function (err, contacts) {
// The contacts are populated correctly with the proper nestedModel
contacts.forEach(function (rec) {
// This will log the person
console.log('person', rec.person.toJSON());
rec.person.toJSON({transform: function (doc, ret) {
// It's the nested model instead of the person object expected.
console.log('not the person!?', doc);
}, function (err) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment