Comments (2)
Hello!
I've tested your code.
Firstly - you don't need to initialize mongoose-pureautoinc twice on the same mongoose connection. If you remove second initialization in your first example everything must be alright.
Secondly - if you call initialization with second parameter you overriding previous settings of plugin. It serves for your own counter collection name only but not for different counters.
There is an example of using plugin with two different models.
var dbName = 'test',
mongoose = require('mongoose'),
Schema = mongoose.Schema,
db = mongoose.createConnection('127.0.0.1', dbName),
pureautoinc = require('mongoose-pureautoinc');
pureautoinc.init(db);
// Declaration of schemas and models
var schemaPerson = new Schema({
name: String,
address: String
});
schemaPerson.plugin(pureautoinc.plugin, {
model: 'Person',
field: 'filingNumber',
start: 100
});
var Person = db.model('Person', schemaPerson);
var schemaStreet = new Schema({
title: String
});
schemaStreet.plugin(pureautoinc.plugin, {
model: 'Street',
field: 'filingNumber',
start: 100
});
var Street = db.model('Street', schemaStreet);
// Using of models
var person = new Person({
name: 'Rocky Balboa',
address: '1818 Tusculum st, Philadelphia, PA 19134'
});
person.save(function (err, res) {
console.log('New person added:');
console.log(res);
});
var street = new Street({
title: 'Tusculum'
});
street.save(function (err, res) {
console.log('New street added:');
console.log(res);
});
from mongoose-pureautoinc.
It worked!
I thought wrong because I'm using a file for each model but now is Ok
thanks for the reply ...
hugs
Pineli
from mongoose-pureautoinc.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose-pureautoinc.