Моя цель состоит в том, чтобы клонировать/расширить общую схему с помощью разных коллекций, есть два способа достижения моей цели, я хотел бы знать разницу между этими способами:
const extendSchema = (Schema, definition, options) =>
new MongooseSchema(Object.assign({}, Schema.obj, definition), options);
const CommonSchema = new MongooseSchema({
name: {
type: String,
unique: true,
},
logo: String,
owner: {
name: String,
avatar: String,
reference: {
type: ObjectId,
ref: 'User',
},
},
});
const AnthorSchema = extendSchema(CommonSchema, { periverImage: String });
И второй:
const CommonSchema = new MongooseSchema({
name: {
type: String,
unique: true,
},
logo: String,
owner: {
name: String,
avatar: String,
reference: {
type: ObjectId,
ref: 'User',
},
},
});
const AnthorSchema = CommonSchema.clone();
AnthorSchema.add({ previewImage: String });