Coder Social home page Coder Social logo

Comments (7)

ramiel avatar ramiel commented on May 14, 2024

Yes is possible, simply recall the plugin several times for different fields. Here an example:

UserSchema = mongoose.Schema({
    name: String,
    like: Number,
    visits: Number
});

UserSchema.plugin(AutoIncrement, {id: 'like_counter', inc_field: 'like', disable_hooks: true});
UserSchema.plugin(AutoIncrement, {id: 'visits_counter',inc_field: 'visits'});

Maybe in a future will be possible to do it in a single call but for now this is the way.

from mongoose-sequence.

bokzor avatar bokzor commented on May 14, 2024

I tried that way but the wrong field is used.

Let's admit I initialize that way :

InvoiceSchema.plugin(AutoIncrement, {id: 'invoice_in', inc_field: 'invoiceIn', disable_hooks: true});
InvoiceSchema.plugin(AutoIncrement, {id: 'invoice_out', inc_field: 'invoiceOut', disable_hooks: true});

If I use this method, It's the field InvoiceOut that is incremented ... :-/

invoice.setNext('invoice_in', function(err, invoice){
  invoice.save();
});

from mongoose-sequence.

ramiel avatar ramiel commented on May 14, 2024

Ok, give me time to check it ok?I'll be back to you soon

from mongoose-sequence.

ramiel avatar ramiel commented on May 14, 2024

There was a bug. Now I created a test. Can you please check the version on develop?
I'll publish the new version lately in any case.

from mongoose-sequence.

ramiel avatar ramiel commented on May 14, 2024

I also noticed that the "setNext" method do not save the document which is maybe the desired behavior. I'll implement an option for this or I'll accept any PR :)

from mongoose-sequence.

bokzor avatar bokzor commented on May 14, 2024

Great ! Thanks for your rapidity. I'm going to look at It

from mongoose-sequence.

ramiel avatar ramiel commented on May 14, 2024

Version 3.0.1 is published and should solve this problem.
Another change is that now when you call setNext the document is already saved so you don't need to save it manually anymore. In your example

invoice.setNext('invoice_in', function(err, invoice){
    // The next line must be removed because invoice is already saved
    // invoice.save();
});

In a next version this will be an option.

from mongoose-sequence.

Related Issues (20)

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.