Not working as expected 🤔 #14814
-
I may be missing something because some of my code is not working as expected. For example: interface IAccount {
name: String;
email: String;
password: String;
}
const AccountSchema = new Schema<IAccount>();
export const Account = model('account', AccountSchema);
// -- IN ANOTHER FILE --
const createdAccount = await Account.create({
name: 'Hello World',
email: '[email protected]',
password: 'strong1234'
});
console.log(createdAccount);
// -- OUTPUT --
{ _id: new ObjectId('66c17b5d4a5edf95928b918d'), __v: 0 } According to the docs this should work, however, none of the properties are saved (I checked with Compass). I got a strange behavior when selecting too: const existingAccount = await Account.findOne({ email: '[email protected]' });
console.log(existingAccount);
/*
{
_id: new ObjectId('66be3f54fff3e68e10d4b06c'),
name: 'Hello World',
email: '[email protected]',
password: 'strong1234'
}
*/
console.log(existingAccount.name); // --> undefined
console.log(existingAccount.toObject().name); // --> 'Hello World'
const existingAccountTwo = await Account.findOne({ email: '[email protected]' }).lean();
console.log(existingAccountTwo.name); // --> 'Hello World' Although the docs use My node version is |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I ended up using the mongodb driver. |
Beta Was this translation helpful? Give feedback.
-
The issue is that your schema is empty: |
Beta Was this translation helpful? Give feedback.
I ended up using the mongodb driver.