npm.io
0.1.0 • Published 5 years ago

mongoose-schema-clone

Licence
MIT
Version
0.1.0
Deps
1
Size
12 kB
Vulns
0
Weekly
0
Stars
2

Mongoose Schema Clone

Version Version

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.

FEATURES:

  • Deep Clone Schema
  • Copy paths, virtuals, getters, setters, indexes, methods, and statics

INSTALLATION:

npm install --save mongoose-schema-clone
USAGE:
const mongooseSchemaClone = require("mongoose-schema-clone");
EXAMPLE:
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 }
        }] 
    }
});
SOURCE:

The source is mongoose-npm method add().

const mongoose = require("mongoose");

module.exports = (Schema, Definition) => {
    return new mongoose.Schema(Definition).add(Schema);
}
CONTACT US:

Email: turivishal@gmail.com

LICENSE:

Mongoose Schema Clone is released under the MIT License.

Keywords