DEV Community

Salah Hasanin
Salah Hasanin

Posted on

How to get a specific object from an array field with mongoose [duplicate]

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…

Top comments (0)