mongoose-schema-json-parse

1.0.1 • Public • Published

mongoose-schema-json-parse

mongoose schema serialize

Install

npm install mongoose-schema-json-parse

Use

const mongoose = require('mongoose');
const {json2schema, schema2json} = require('mongoose-schema-json-parse');

const AccountSchema = new mongoose.Schema({
    uid: {
        type: Number,
        required: true,
        unique: true,
        index: true
    },
    nickname: String,
    sex: {
        type: Number,
        enum: [0, 1, 2],
        default: 0
    },
    email: {
        type: String,
        unique: true,
        sparse: true,
    },
    others: {}
}, {timestamps: true});
AccountSchema.index({'others.score': 1}, {unique: true, sparse: true});
AccountSchema.index({'others.level': 1}, {unique: true, sparse: true});

let json1 = schema2json(AccountSchema)
console.log(json1)

let schema = json2schema(json1)

let json2 = schema2json(schema)
console.log(json2)

Package Sidebar

Install

npm i mongoose-schema-json-parse

Weekly Downloads

1

Version

1.0.1

License

Apache-2.0

Unpacked Size

16 kB

Total Files

5

Last publish

Collaborators

  • lyrstar