Trying to solve a perplexing exception that has left me scratching my head for over an hour.
Error message: CastError: Cast to ObjectId failed for value "[email protected]" at path "_id" for model "Account"
My goal is to fetch an Account using the email address. Here is the query I am using:
export async function getPendingRecipients(user_id, email_address) {
const account = await Account
.find({email: email_address})
.exec();
return true;
}
Below is the Schema object I am working with:
const userGmailSchema = new Schema({
id: {
type: String,
unique: true
},
displayName: String,
image: Object,
accessToken: String,
user: {
type: Schema.Types.ObjectId,
ref: 'User'
},
refreshToken: {
type: String,
default: null
},
email: {
type: String,
unique: true
},
emails: [
{
type: Schema.Types.ObjectId,
ref: 'Emails'
}
]
});