claytongulick / mongoose-json-patch Goto Github PK
View Code? Open in Web Editor NEWA utility for applying RFC6902 JSONPatch operations to mongoose models
License: MIT License
A utility for applying RFC6902 JSONPatch operations to mongoose models
License: MIT License
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.