lib/plugin.js
function (done) {
            var select = {};
            select[pathName] = 1;

            Model.findOne({_id: model}, select, function (err, doc) {
              if (err) return done(err);
              if (!doc) return done(null, []);

              done(null, doc[pathName].reduce(function (o, friend) {
                o[friend._id] = friend.toObject();
                return o;
              }, {}));
            });
          }
function (done) {
            var select = {};
            select[pathName] = 1;

            Model.findOne({_id: model}, select, function (err, doc) {
              if (err) return done(err);
              if (!doc) return done(null, []);

              done(null, doc[pathName].reduce(function (o, friend) {
                o[friend._id] = friend.toObject();
                return o;
              }, {}));
            });
          }
function ( done ) { var select = { } ; select [ pathName ] = 1 ; Model . findOne ( { _id : model } , select , function ( err , doc ) { if ( err ) return done ( err ) ; if ( ! doc ) return done ( null , [ ] ) ; done ( null , doc [ pathName ] . reduce ( function ( o , friend ) { o [ friend . _id ] = friend . toObject ( ) ; return o ; } , { } ) ) ; } ) ; }
Reduce local friend docs to map which will be populated and then combined with the queried remote friends to generate the resulting array
Reduce local friend docs to map which will be populated and then combined with the queried remote friends to generate the resulting array