Coder Social home page Coder Social logo

Comments (3)

ramiel avatar ramiel commented on May 28, 2024 1

To be honest, I don't know. I never tried it on CosmosDB. There's nothing special in this middleware, so as long as basic operations on mongo are supported on cosmos, it should work. I can't tell you more, sorry

from mongoose-sequence.

sghoe avatar sghoe commented on May 28, 2024

hello ramiel, thank you for your quick response.

While debugging it seems that every time the lastErrorObject.updatedExisting is false at the counter and it puts in the startSeq everytime

// lastErrorObject.updatedExisting is true if new entry was upserted if (_.has(counter, 'lastErrorObject') && !counter.lastErrorObject.updatedExisting) { return callback(null, startSeq); }

we are using "mongoose": "5.13.14",

do you have any additional ideas?

from mongoose-sequence.

perfusorius avatar perfusorius commented on May 28, 2024

Hello @sghoe , Hello @ramiel

I also have this issue. My app was using MongoDB in MongoCloud and everything was working as expected. But a switch to Azure CosmosDB was neccessary and suddenly mongoose-sequence stopped working.

Through local debugging and testing I found the cause(s) and how to fix them.

Cosmos/Mongo will prevent inserting and updating of Counters documents when the uniqueness check in the defined index is in place. So changing (line 200)

    CounterSchema.index({ id: 1, reference_value: 1 }, { unique: true });

to

    CounterSchema.index({ id: 1, reference_value: 1 });

is the first step. Since you already use upserts with filtering for id and reference_value uniqueness of all documents should still be given.

As @sghoe mentions in the above comment in the callback in Sequence.prototype._createCounter always startSeq is returned to the callback. When the upsert was successful then counter object in that callback has a property lastErrorObject, and a property value that contains the created document. That means it did work and in that case, according to how I understood your logic, the callback that is then called should get null as its second parameter instead of startSeq.
So my second proposal would be to change (lines 389 ff.)

        if (_.has(counter, 'lastErrorObject') && !counter.lastErrorObject.updatedExisting) {
          return callback(null, startSeq);
        }

to

        if ('value' in counter && 'seq' in counter.value) {
          return callback(null, null);
        }
        else if (_.has(counter, 'lastErrorObject') && !counter.lastErrorObject.updatedExisting) {
          return callback(null, startSeq);
        }

With these two changes I could get my app to work with CosmosDB. Counter-documents where created again as expected and seqvalues were increased correctly for each new document in the watched collections.

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.