1.1.0 • Published 6 years ago

mongoose-unique-params-plugin v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

mongoose-unique-params-plugin

This plugin adds a static function that analyzes the model and allows you to get a list of keys that are unique

Install

npm i mongoose-unique-params-plugin

Usage

const plugin = require("mongoose-unique-params-plugin");

let schema = new mongoose.Schema({
    name: { type: String, unique: true },
    title: { type: String},
    flags: {
    	checked: { type: Boolean, unique: true }
    }
});

schema.plugin(plugin);

let model = mongoose.model("test", schema);

console.log(model.uniqueParams()) // { name: true, flags: { checked: true } }

console.log(model.uniqueParams(true)) // { name: true, flags.checked: true }

API

model.uniqueParams(flatten).

flatten - option that allows you to expand an object. Optional. Default false.

License

MIT © nlapshin