mongoose-unique-params-plugin

1.1.0 • Public • Published

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

/mongoose-unique-params-plugin/

    Package Sidebar

    Install

    npm i mongoose-unique-params-plugin

    Weekly Downloads

    0

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    2.83 kB

    Total Files

    4

    Last publish

    Collaborators

    • nlapshin