-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] this.increment is not a function #64
Comments
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, ***@***.***> 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
<#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; When I have time I can write a small repo reproducing.
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. 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 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 ? |
While we have a mongoose schema with a subdocument, it's expected to don't add hooks to this internal document, or it will cause errors. Fix eoin-obrien#64
Ok, I've the same issue, blocking our feature development, I've forked the repo, fixed the issue then submited a pull request. |
@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. |
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:
I am using the latest version of Mongoose & MongoDB.
The text was updated successfully, but these errors were encountered: