Git Product home page Git Product logo

mongoose-json-patch's People

Contributors

claytongulick avatar emilrowland avatar sebattestis avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mongoose-json-patch's Issues

TypeError: Cannot read property 'options' of undefined

Hello,

We are running into this issue, and I thought I'd write to you after spending some time examining both side of the code:

TypeError: Cannot read property 'options' of undefined
    at JSONPatchMongoose.populatePath (/vlab_shared/vl-models/node_modules/mongoose-patcher/json_patch_mongoose.js:376:33)
    at next (/vlab_shared/vl-models/node_modules/mongoose-patcher/json_patch_mongoose.js:86:28)
    at JSONPatchMongoose.apply (/vlab_shared/vl-models/node_modules/mongoose-patcher/json_patch_mongoose.js:93:23)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at runNextTicks (internal/process/task_queues.js:62:3)
    at processImmediate (internal/timers.js:434:9)
    at model.schema.methods.jsonPatch (/vlab_shared/vl-models/node_modules/mongoose-patcher/index.js:12:9)

Patch has this form:

[{"op":"replace","path":"/version","value":6},{"op":"replace","path":"/modification_date","value":"2023-07-21T13:30:11.400Z"},{"op":"replace","path":"/accounts/main","value":["60a2facac1f8e816afb0645d","60a2facac1f8e87e26b0645e","62d525acf4e903001169d7d0"]}]

And the relevant part of the object is this:

        "accounts" : {
                "main" : [
                        "60a2facac1f8e816afb0645d",
                        "60a2facac1f8e87e26b0645e"
                ],
                "linked" : {
                        "60a2facac1f8e816afb0645d" : 2,
                        "62d525acf4e903001169d7d0" : 2
                }
        }

It seems like the array is causing that issue and I know that we've had to change the schema after running into unrelated issues:

const mongoose = require('mongoose');

module.exports = {
    type: {
        main: [String],
        linked: mongoose.Mixed,
        old: mongoose.Mixed
    },
    set: function (newVal) {
        if (!this.accounts.old) {
            this.accounts.old = {};
        }

        this.accounts.old.main = (this.accounts.main || []).slice();
        this.accounts.old.linked = Object.assign({}, this.accounts.linked);

        return newVal;
    },
    default: {
        main: [],
        linked: {}
    },
    _id: false
};

This is a POJO schema imported as vlAccounts and used in the document that is patched like that:

        accounts: vlAccounts,

Upon inspection it seems that the accounts array loaded from the document is lacking a $schema() method as well as a _schema property. We tried to understand which part of Mongoose is responsible for populating this method and property but at this stage I thought I'll create an issue here - any help would be appreciated. I don't know for how many years we have been using mongoose-patcher but it's certainly a core part of our application, thank you for maintaining it. I appreciate the time you would spend reading and replying to this and I will forward my issue to the project owner with a recommendation to make a donation towards the project.

The version we are using is 0.2.15.

Cheers,
Svetoslav

Remove field

Shouldn't the remove operator remove the field by setting it to undefined instead of null.
For example I use the exsist operator to see if a field is set, but as its set to null it returns the record.

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.