mongoose-unique-params-plugin
v1.1.0
Published
This plugin adds a static function that analyzes the model and allows you to get a list of schema keys(or paths) that are unique
Downloads
2
Readme
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