Comments (7)
Here is an example to reproduce the issue:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const patchHistory = require('mongoose-patch-history').default;
const PostSchema = new Schema({
_id: { type: String },
title: { type: String, required: true },
comments: Array
}, {_id:false});
PostSchema.plugin(patchHistory, { mongoose, name: 'postPatches' });
const Post = mongoose.model('Post', PostSchema);
let post= await Post.create({_id: "post", title:"first", comments:["ok"]});
console.log('Ok', post);
post= await Post.findOneAndUpdate({_id:"inexistence"}, {title:"new", comments:["fine"]});
console.log(post);
/*
Ok { comments: [ 'ok' ], _id: 'post', title: 'first', __v: 0 }
2018-06-01T14:03:26.169Z - error: Unhandled Rejection at: Promise [object Promise] - reason ==> TypeError: Cannot set property '_original' of null
at C:\examples\node_modules\mongoose-patch-history\lib\index.js:193:21
at tryCatcher (C:\examples\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\examples\node_modules\bluebird\js\release\promise.js:512:31)
...
*/
from mongoose-patch-history.
Hi @codepunkt
The mongodb version I'm using is: 3.6.4
Mongoose version: 5.0.8
mongoose-patch-history
: 1.3.0
Sorry I might not be able to prepare a reproducible sample soon enough. Will try my best!
from mongoose-patch-history.
This error occurs, for me, when I try to perform an update with a nonexistent ObjectId in the collection.
from mongoose-patch-history.
@THPubs @florojunior Thanks for reporting this problem and thanks for adding additional context as to how/when this occurs.
- Which versions of
mongodb
,mongoose
andmongoose-patch-history
do you use? - Can you provide a minimum, reproducible example?
from mongoose-patch-history.
I suggest to just ignore the history if the document was not updated, at line 173 add: if(!doc) next();
schema.post('findOneAndUpdate', function (doc, next) {
if(!doc) next(); //<-- here
if (!this.options.new) {
return postUpdateOne.call(this, {}, next);
}
from mongoose-patch-history.
I ran into the same bug today!
I observed the following: We call findOneAndUpdate in our code and the query does not match anything.
The following line then causes a null pointer: https://github.com/codepunkt/mongoose-patch-history/blob/master/lib/index.js#L177
This is because doc
is null in this case.
from mongoose-patch-history.
Anyone up for providing a PR for this? I don't have the time at the moment.
from mongoose-patch-history.
Related Issues (20)
- mongoose 6.4.4 not work HOT 4
- Close version with latest changes HOT 2
- Patches are not deleted if I use deleteMany({}) HOT 1
- An in-range update of mongoose is breaking the build 🚨 HOT 28
- Cannot read property '$__' of undefined HOT 1
- An in-range update of fast-json-patch is breaking the build 🚨 HOT 4
- Usage of old mongoose index practice HOT 2
- Is there an option to track author of changes HOT 5
- An in-range update of mongoose is breaking the build 🚨 HOT 45
- Bluebird promises module is a run-time dependency!
- Is this repo still active? HOT 9
- Breaking change in new released version v1.4.0: MongoError: unknown top level operator: $push HOT 6
- Cannot perform an `add` operation at the desired path HOT 6
- findOneAndUpdate with options { new: true, rawResult: true } throws Error HOT 6
- Bug: With the plugin, updateOne hangs, if nothing was found HOT 8
- Timeout upon saving a new document HOT 7
- Adding lean() causes TypeError: document.data is not a function HOT 9
- Not capturing delete events. HOT 7
- @types/mongoose-patch-history HOT 4
- Make name of internal data() method configurable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose-patch-history.