I have two models, one of which is User , and the other is Reservation . I want to embed a User object in every reservation. The user has already been created and is stored in the user collection. When I try to create a new backup object, my User object goes through the pre-save method and ultimately fails because there is a unique username field. Is there a way around this precautionary method when embedding objects in another collection, or is my approach completely wrong? My code for the backup scheme. Thanks!
import User from './../users/users.model'; const Schema = mongoose.Schema; export default new Schema({ user: { type: User } });
Edit: when I clearly define the scheme, it bypasses the pre-save method (which makes sense), but if I want to change the scheme, I need to change it in two different places.
source share