wclr / mongoose-fill

Virtual async fileds for mongoose.js
61 stars 8 forks source link

Work with aggregation #14

Closed Aeonrush closed 8 years ago

Aeonrush commented 8 years ago

When I tried to use mongoose-fill with aggregation

  require('mongoose').model('Art').aggregate([
    {$lookup: {
      from: 'likes',
      localField: '_id',
      foreignField: 'art',
      as: 'likes'
    }},
    {$sort: {_id: -1}},
  ]).fill('likesCount').exec(callback);

I got an error

TypeError: require(...).model(...).aggregate(...).fill is not a function at router.get

When I write

 require('mongoose').model('Art').find({}).fill('likesCount').exec(callback);

all works fine I think monggose-fill not designed for work in this scenario?

wclr commented 8 years ago

Yes I think that is because mongoose aggregate is just a wrapper for native aggregate which is not supposed to always return documents, but something else projected.

Aeonrush commented 8 years ago

Thanks a lot 😄