@alakermi/mongooseuuid
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

mongooseuuid 👋

NPM version Build Status Coverage Status

generate random unique uuid for Mongoose schema

Prerequisites

  • npm >=5.5.0

Install

To use mongooseuuid for an existing mongoose schema you'll have to require and plugin mongooseuuid into the existing schema.

$ npm install @alakermi/mongooseuuid --save

Usage

import mongoose from 'mongoose';
import mongooseuuid from 'mongooseuuid';
 
mongoose.connect('mongodb://localhost/Default');
 
// Default options
let options = {
  field:"myid" // default options 'uniqueid'
};
 
// Add the plugin to the schema with default options
let Schema = mongoose.Schema({ myid: 'string', });
Schema.plugin(mongooseuuid(options));
 
// Create a model
let Guest = mongoose.model('guest', Schema);
 
// Create and and save document
let guest = new Guest({})
await guest.save()

Options

  • field: name of the field to affec uuid for it . The default is 'uniqueid'. this options is required or it will throw an error

Author

👤 Abdelhak Akermi

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!


Package Sidebar

Install

npm i @alakermi/mongooseuuid

Weekly Downloads

0

Version

0.0.4

License

MIT

Unpacked Size

6.45 kB

Total Files

7

Last publish

Collaborators

  • alakermi