Nunchaku Pizza Master

    mongoose-plugin-drop-duplicates

    0.0.3 • Public • Published

    mongoose-plugin-drop-duplicates

    A simple plugin that enforces unique fields within documents by dropping existing duplications.

    Install

    npm install --save mongoose-plugin-drop-duplicates
    

    Uaage

    A special key dropDups could be used to identify the fields you wish to be unique.

    const Schema = mongoose.Schema;
    const schema = new Schema({
      email: {
        type: String,
        dropDups: true
      }
    });
     
    schema.plugin(require('mongoose-plugin-drop-duplicates'));
     
    const Subscription = mongoose.model('Subscription', schema);
     
    ...
     
    new Subscription({email: 'abc@example.com'}).save(); // successful
    ...
    new Subscription({email: 'abc@example.com'}).save(); // also successful, but previous document is removed
    ...
    Subscription.find({}) // only got one record with abc@example.com

    Author

    Jason Yu

    License

    ISC

    Keywords

    none

    Install

    npm i mongoose-plugin-drop-duplicates

    DownloadsWeekly Downloads

    0

    Version

    0.0.3

    License

    ISC

    Last publish

    Collaborators

    • ycm.jason