You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mongo newbie here 👋 May I ask if timestamps: true is intentional? Right after that with toJSON they are being removed.
Is there an implicit reason?
Actually there are options for version key, timestamps and id, so they could all be controlled by passing the options for a schema, what is the point of toJSON and all that transformation?
constuserSchema=mongoose.Schema({/* schema definition here */},{timestamps: true});userSchema.plugin(toJSON);
The toJSON plugin applies the following changes in the toJSON transform call:
removes __v, createdAt, updatedAt, and any schema path that has private: true
replaces _id with id
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
Mongo newbie here 👋 May I ask if
timestamps: true
is intentional? Right after that withtoJSON
they are being removed.Is there an implicit reason?
Actually there are options for version key, timestamps and id, so they could all be controlled by passing the options for a schema, what is the point of toJSON and all that transformation?
Beta Was this translation helpful? Give feedback.
All reactions