Socket
Socket
Sign inDemoInstall

mongoose-draft

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mongoose-draft

mongoose draft plugin


Version published
Maintainers
1
Install size
1.35 MB
Created

Readme

Source

mongoose-draft

Mongoose draft plugin to disable the model validation

Installation

Install via npm:

$ npm install mongoose-draft

Documentation

Options

  • isDraft set the initial value (optional, default true)
  • fieldName set fieldName value, use it only is you're already using the default value somewhere else (optional, default _is_draft)

Methods

instance.setIsDraft(isDraft)

Set the value of isDraft

Virtual fields

instance.isDraft

Get/Set the value of isDraft

Examples

var mongoose = require('mongoose');
var draft = require('mongoose-draft');

var TestSchema = new mongoose.Schema({
  'label_1': {
    'type': String,
    'required': true,
  },
  'label_2': {
    'type': String,
    'required': false,
  },
});

TestSchema.plugin(draft, { isDraft: true });

var TestDraft = mongoose.model('Test_draft', TestSchema);

var model = new TestDraft()

model.validate(); // -> return a promise fulfilled without any validation errors
model.isDraft = false;
model.validate(); // -> return a promise fulfilled with validation errors

model.setIsDraft(true);

model.save(); // -> return a promise fulfilled with the model instance
model.setIsDraft(false);
model.save(); // -> return a promise fulfilled with validation errors

Contributing

This project is a work in progress and subject to API changes, please feel free to contribute

Keywords

FAQs

Last updated on 04 May 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc