Giter Site home page Giter Site logo

Multi schema about mongoose-pureautoinc HOT 2 CLOSED

pineli avatar pineli commented on August 16, 2024
Multi schema

from mongoose-pureautoinc.

Comments (2)

dmitry-ilin avatar dmitry-ilin commented on August 16, 2024

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.

pineli avatar pineli commented on August 16, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.