mongoose-update-if-current
mongoose-update-if-current copied to clipboard
[BUG] this.increment is not a function
I just added the plugin using: const { updateIfCurrentPlugin } = require('mongoose-update-if-current'); // insert mongoose plugins mongoose.plugin(updateIfCurrentPlugin); In the file where my server is declared. If I understood the manual correctly this should enable it.
However when I try to add any new document I currently receive the following error in Postman:
{
"message": "this.increment is not a function",
"error": {}
}
I am using the latest version of Mongoose & MongoDB.
Thanks for the bug report! Could you upload a minimal repo to reproduce the error?
Also, what version of Node.js are you using, and are you using any transpilers, for example, TypeScript or Babel?
On Wed 6 Nov 2019, 09:07 RuudVerhoef, [email protected] wrote:
I just added the plugin using: const { updateIfCurrentPlugin } = require('mongoose-update-if-current'); // insert mongoose plugins mongoose.plugin(updateIfCurrentPlugin); In the file where my server is declared. If I understood the manual correctly this should enable it.
However when I try to add any new document I currently receive the following error in Postman:
{ "message": "this.increment is not a function", "error": {} }
I am using the latest version of Mongoose & MongoDB.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/eoin-obrien/mongoose-update-if-current/issues/64?email_source=notifications&email_token=AD4OXAKRA4IFZWOK2QMK3CDQSKCNHA5CNFSM4JJRZPIKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HXFE23A, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4OXANPRLGCLMPJHM3AZNDQSKCNHANCNFSM4JJRZPIA .
I am not using any transpilers. My NodeJS version is 10.16.0. I can try to reproduce it later today or tomorrow using a minimal example. I hoped this might had been a known issue resulting from wrong usage.
I also had this issue in a nested schema when using the global setup;
There is not much to it, below is the basic setup. Since there is no __v
in the subdocument I believe that is where the problem is.
When I have time I can write a small repo reproducing.
"mongoose": "^5.7.8", "mongoose-update-if-current": "^1.3.2",
const aliasSchema = new mongoose.Schema({
name: {type: String}
},{ timestamps: true })
const userSchema = new mongoose.Schema({
email: {type: String, unique: true},
aliases: [aliasSchema]
},{ timestamps: true })
I could reproduce it with using different options between the main schemas and nested schema.
Having different versionKey between schemas can trigger the same error.
In my case, I configured the plugin globally and wanted to use versioning only on the main schemas with the following options :
{ toObject: { virtuals: true }, timestamps: true, versionKey: 'v' }
The nested schemas used default options, hence the versionKey name was '__v' and it never found an increment method on any of them.
I tried disabling versioning on nested schema with options { versionKey: false }
but that triggers the error "document schema must have a version key".
So I guess we can't use a global plugin configuration if some schemas won't be versioned, right ? Is there any way to simply exclude nested schema from being versioned by the plugin ?
Ok, I've the same issue, blocking our feature development, I've forked the repo, fixed the issue then submited a pull request. @eoin-obrien If you cannot check & accept this PR and release in following days, I'll fork npm too, for our production usage.
@Nainterceptor Merged, thanks!
The fix is live on npm as version 1.4.0 now.
I believe I've just encountered this issue while running version 1.4.0! Everything works OK if I explicitly add this plugin to the top-level models, but global configuration is a no go, unfortunately :/.
@chiubaka Thanks for flagging this, I'll start investigating! Could you share the repo or the code snippets to reproduce the issue?
Hello! Thanks for your fast response. Unfortunately, the repo in question is private and proprietary... I'll try to set up a repro repo for you in the next week, if I can find a little time to do so.