i need create model (new) identical existing 1 (original). new model have new field ("expiresat") want use mongodb time live (ttl) feature. for design purposes don't want store new model in same collection original (only new model should have ttl feature).
example:
//original schema var originalschema = new schema({ id: { type: schema.types.objectid }, name: { type: string }, description: { type:string }, }); //new schema var newschema = new schema({ id: { type: schema.types.objectid }, name: { type: string }, description: { type:string }, expiresat: { type: date, default: date.now, expires: 24*60*60 } });
how can achieve using inheritance?
mongoose discriminators schema inheritance mechanism. enable have multiple models overlapping schemas on top of same underlying mongodb collection. details talked in link.
var originalschema = new schema({ id: { type: schema.types.objectid }, name: { type: string }, description: { type:string }, }); var newschema = new schema({ expiresat: { type: date, default: date.now, expires: 24*60*60 } }); var original = mongoose.model('original', originalschema); var newsch = original.discriminator('newsch', newschema);
Comments
Post a Comment