I'm doing a find on a nested array object and one of it's property. But the result is null.
i'm search for this object with the sub-object "externalAccounts" and it's extId 106100668938302013942.
This is my query:
let user = await UserProfile.findOne({'externalAccounts': {$elemMatch: {extId: id}}});
Returning null. I also tried the externalAccounts.extId way but won't work as externalAccounts is an array. Any suggestions?
My Schemas:
const UserProfileSchema = new Schema(
externalAccounts:[{
type: Schema.Types.ObjectId,
ref: 'ExternalAccount',
default: [],
}]
}
const ExternalAccountSchema = new Schema(
{
type: { type: String },
extId: { type: String },
token: {type: String,},
},
{ usePushEach: true,}
);
module.exports = Mongoose.model('ExternalAccount', ExternalAccountSchema);