Thursday, 1 June 2017

Mongoose populate, keep only one field of the schema

the following line is how I do a populate :

Model.find({filter: myFilter}).populate('myRef', 'theFieldIWant');

It gives me the following structure :

{ 
  myRef: { _id: 592fe8f2a69600bc0828e462, theFieldIWant: 'value' },
  ...
}

But what I want is :

{ 
  myRef: 'value',
  ...
}

How could I do it ?



via boehm_s

No comments:

Post a Comment