kasongoyo / mongoose-sequence-plugin Goto Github PK
View Code? Open in Web Editor NEWMongoose plugin to auto-increment alphanumeric field
Mongoose plugin to auto-increment alphanumeric field
i.e rather than use external model to lookup to the past id and save next id, it will be possible to lookup on the same schema.
Unless there is hidden benefits of using external schema
i.e
generated_id-suffix
example
03-75-AD-WOF
i.e
prefix-generateted_id
example
ZOD-00-07-01
Let the following schemas
var mongoose = require('mongoose');
var sequenceGenerator = require('mongoose-sequence-plugin');
var Schema = mongoose.Schema;
var childSchema= Schema({
childID: String,
someField: String
});
var parentSchema = Schema({
parentID: String
children: [childSchema]
});
childSchema.plugin(sequenceGenerator, {
field: 'childID',
startAt: '0'
});
parentSchema.plugin(sequenceGenerator, {
field: 'parentID',
startAt: '0'
});
I want to push subdocoments to children by doing:
this.findOneAndUpdate({parentID: id}, {$push: {children: {$each: childrenData}}, { new: true, runValidators:true }, function (error, data) {
//
});
This way no childID is generated in pushed subdocuments.
{ MongoError: E11000 duplicate key error collection: enmskeleton.blobs index: ne
wid_1 dup key: { : "PK-9" }
Example if i want my generated id to have below structure
0059-345-SJE
How would i be able to acheive that with you library?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.