@alakermi/mongooseuuid
v0.0.4
Published
generate random unique uuid for Mongoose schema
Downloads
2
Maintainers
Readme
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
- Github: @alakermi
🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!