我一直在为一个奇怪的异常而苦苦挣扎,一小时后仍然对它感到困惑。强制转换为ObjectId在Mongoose中的值错误失败findOne
CastError: Cast to ObjectId failed for value "[email protected]" at path "_id" for model "Account"
我试图通过电子邮件地址检索帐户。这里是我的查询
export async function getPendingRecipients(user_id, email_address) {
const account = await Account
.find({email: email_address})
.exec();
return true;
}
这是我的Schema对象
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'
}
]
});