Deep clone and Returns a copy of the schema, Adds key path / schema type pairs to this schema and You can also add another schema and copy over all paths, virtuals, getters, setters, indexes, methods, and statics.
- Deep Clone Schema
- Copy paths, virtuals, getters, setters, indexes, methods, and statics
npm install --save mongoose-schema-clone
const mongooseSchemaClone = require("mongoose-schema-clone");
const mongoose = require("mongoose");
const mongooseSchemaClone = require("mongoose-schema-clone");
const ParentSchema = new mongoose.Schema({
name: { type: String },
logo: { type: String }
});
const ChildSchema = mongooseSchemaClone(ParentSchema, {
address: {
type: [{
location: { type: String },
city: { type: String },
state: { type: String },
country: { type: String },
postalCode: { type: String }
}]
}
});
The source is mongoose-npm method add().
const mongoose = require("mongoose");
module.exports = (Schema, Definition) => {
return new mongoose.Schema(Definition).add(Schema);
}
Email: [email protected]
Mongoose Schema Clone is released under the MIT License.