Given a schema like this:
UserSchema = new Schema({
  name: String,
  donations: [
    {
      amount: Number,
      charity: {
        type: Schema.Types.ObjectId,
        ref: 'charity'
      }
    }
  ]
});
I have the (string) ids of a user and of a nonprofit and I want to get the amount the user donated. Im using this query with lodash:
User.findOne({
  _id: userId
}, function(err, user) {
  var amount = _.find(user.donations, {charity: charityId});
  console.log("the amount is: ", amount);
});
Here the amount returns undefined even though it shouldn't also im guessing i shouldn't have to use lodash. What's the right way to get to the amount donated given a specific userId and charityId?
 
    