initialize mongoose collection with default documents

Viewed 29

is there a way to initialize the mongoose collection with default documents I did take a look at mongoose docs i didn't find a hook to help me achieve what I want

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import * as mongoose from 'mongoose';

export type NetworkDocument = Network & mongoose.Document;
@Schema({
  versionKey: false,
  timestamps: { createdAt: 'created-at', updatedAt: 'updated-at' },
})
export class Network {
  @Prop({ unique: true })
  'network-id': number;

  @Prop({ required: true })
  'labels': string[];


}
export const NetworkSchema = SchemaFactory.createForClass(Network);

NetworkSchema.pre('save', () => {
  console.log('network model saved');
});

0 Answers
Related