I want to add dynamic fields to Mongoose Schema every time before add/update record. Since, I have defined the fields into the separate JSON file and want the same JSON fields to be added dynamically every time to the Mongoose schema. Is this possible and how to do that?
Example Simple Modal:
const blogSchema = new Schema({
title: String, // String is shorthand for {type: String}
body: String,
});
let dynamicfields=[
author: String,
comments: [{ body: String, date: Date }],
date: { type: Date, default: Date.now },
hidden: Boolean,
]
How can I add dynamicFields to schema every time?