Mongoose 5.3 , this.getUpdate is not a function
When I try to execute the update function I got this error. It happen when I added timestamps: true
I navigate to the error and I got this function called in schema.js in mongoose >> lib folder.
function _setTimestampsOnUpdate(next) {
applyTimestampsToUpdate(createdAt, updatedAt, this.getUpdate(),
this.options, true);
applyTimestampsToChildren(this);
next();
}
The above function was used with getUpdate in schema.js. Please help me out with this issue.
:: SCHEMA ::
const assetListSchema = new Schema({userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
name: String,
config: {
showAssetsLibrary: {
type: Boolean,
required: true,
default: true
},
showAssetsDetails: {
type: Boolean,
required: true,
default: true
},
aliasName: {
type: String,
maxlength: 75,
default: ""
}
}},{ timestamps: true});
:: UPDATE function ::
assetListSchema.methods.update = async function (data) {
try {
let asst = this;
data = _.pick(data, ['showAssetsLibrary',
'showAssetsDetails','aliasName']);
if (_.isEmpty(data)) {
emptyError();
}
return await AssetsHierarchy.findByIdAndUpdate(asst._id, {
config: data
}, {
new: true,
fields: {
"config": 1
}
});
} catch (err) {
throw new Error(err.message);
}
}
:: ERROR ::
TypeError: this.getUpdate is not a function
at model._setTimestampsOnUpdate (D:inspectionAppinspection-backendnode_modulesmongooselibschema.js:873:56)
at callMiddlewareFunction (D:inspectionAppinspection-backendnode_moduleskareemindex.js:427:23)
at next (D:inspectionAppinspection-backendnode_moduleskareemindex.js:58:7)
at Kareem.execPre (D:inspectionAppinspection-backendnode_moduleskareemindex.js:86:8)
at Kareem.wrap (D:inspectionAppinspection-backendnode_moduleskareemindex.js:265:8)
at model.$__update (D:inspectionAppinspection-backendnode_moduleskareemindex.js:339:11)
at utils.promiseOrCallback.callback (D:inspectionAppinspection-backendnode_modulesmongooselibhelpersmodelapplyHooks.js:80:30)
at Promise (D:inspectionAppinspection-backendnode_modulesmongooselibutils.js:246:5)
at new Promise ()
at Object.promiseOrCallback (D:inspectionAppinspection-backendnode_modulesmongooselibutils.js:245:10)
at model.objToDecorate.(anonymous function) [as update] (D:inspectionAppinspection-backendnode_modulesmongooselibhelpersmodelapplyHooks.js:79:20)
at update (D:inspectionAppinspection-backendAppcontrollerssettingsasset-hierarchyassetsHierarchyController.js:163:33)
at Layer.handle [as handle_request] (D:inspectionAppinspection-backendnode_modulesexpresslibrouterlayer.js:95:5)
at next (D:inspectionAppinspection-backendnode_modulesexpresslibrouterroute.js:137:13)
at Route.dispatch (D:inspectionAppinspection-backendnode_modulesexpresslibrouterroute.js:112:3)
at Layer.handle [as handle_request] (D:inspectionAppinspection-backendnode_modulesexpresslibrouterlayer.js:95:5)
javascript mongoose mongoose-schema
add a comment |
When I try to execute the update function I got this error. It happen when I added timestamps: true
I navigate to the error and I got this function called in schema.js in mongoose >> lib folder.
function _setTimestampsOnUpdate(next) {
applyTimestampsToUpdate(createdAt, updatedAt, this.getUpdate(),
this.options, true);
applyTimestampsToChildren(this);
next();
}
The above function was used with getUpdate in schema.js. Please help me out with this issue.
:: SCHEMA ::
const assetListSchema = new Schema({userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
name: String,
config: {
showAssetsLibrary: {
type: Boolean,
required: true,
default: true
},
showAssetsDetails: {
type: Boolean,
required: true,
default: true
},
aliasName: {
type: String,
maxlength: 75,
default: ""
}
}},{ timestamps: true});
:: UPDATE function ::
assetListSchema.methods.update = async function (data) {
try {
let asst = this;
data = _.pick(data, ['showAssetsLibrary',
'showAssetsDetails','aliasName']);
if (_.isEmpty(data)) {
emptyError();
}
return await AssetsHierarchy.findByIdAndUpdate(asst._id, {
config: data
}, {
new: true,
fields: {
"config": 1
}
});
} catch (err) {
throw new Error(err.message);
}
}
:: ERROR ::
TypeError: this.getUpdate is not a function
at model._setTimestampsOnUpdate (D:inspectionAppinspection-backendnode_modulesmongooselibschema.js:873:56)
at callMiddlewareFunction (D:inspectionAppinspection-backendnode_moduleskareemindex.js:427:23)
at next (D:inspectionAppinspection-backendnode_moduleskareemindex.js:58:7)
at Kareem.execPre (D:inspectionAppinspection-backendnode_moduleskareemindex.js:86:8)
at Kareem.wrap (D:inspectionAppinspection-backendnode_moduleskareemindex.js:265:8)
at model.$__update (D:inspectionAppinspection-backendnode_moduleskareemindex.js:339:11)
at utils.promiseOrCallback.callback (D:inspectionAppinspection-backendnode_modulesmongooselibhelpersmodelapplyHooks.js:80:30)
at Promise (D:inspectionAppinspection-backendnode_modulesmongooselibutils.js:246:5)
at new Promise ()
at Object.promiseOrCallback (D:inspectionAppinspection-backendnode_modulesmongooselibutils.js:245:10)
at model.objToDecorate.(anonymous function) [as update] (D:inspectionAppinspection-backendnode_modulesmongooselibhelpersmodelapplyHooks.js:79:20)
at update (D:inspectionAppinspection-backendAppcontrollerssettingsasset-hierarchyassetsHierarchyController.js:163:33)
at Layer.handle [as handle_request] (D:inspectionAppinspection-backendnode_modulesexpresslibrouterlayer.js:95:5)
at next (D:inspectionAppinspection-backendnode_modulesexpresslibrouterroute.js:137:13)
at Route.dispatch (D:inspectionAppinspection-backendnode_modulesexpresslibrouterroute.js:112:3)
at Layer.handle [as handle_request] (D:inspectionAppinspection-backendnode_modulesexpresslibrouterlayer.js:95:5)
javascript mongoose mongoose-schema
It's more than likely a problem with your code and not mongoose itself
– kemotoe
Nov 12 '18 at 14:14
Please share yourschemacode
– Mosius
Nov 12 '18 at 14:14
const assetListSchema = new Schema({ userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, name: String, config: { showAssetsLibrary: { type: Boolean, required: true, default: true }, showAssetsDetails: { type: Boolean, required: true, default: true }, aliasName: { type: String, maxlength: 75, default: "" } } }, { timestamps: true });
– Shailesh Jha
Nov 13 '18 at 4:41
assetListSchema.methods.update = async function (data) { try { let asst = this; data = .pick(data, ['showAssetsLibrary', 'showAssetsDetails', 'aliasName']); if (.isEmpty(data)) { emptyError(); } return await AssetsHierarchy.findByIdAndUpdate(asst._id, { config: data }, { new: true, fields: { "config": 1 } }); } catch (err) { throw new Error(err.message); } }
– Shailesh Jha
Nov 13 '18 at 4:43
add a comment |
When I try to execute the update function I got this error. It happen when I added timestamps: true
I navigate to the error and I got this function called in schema.js in mongoose >> lib folder.
function _setTimestampsOnUpdate(next) {
applyTimestampsToUpdate(createdAt, updatedAt, this.getUpdate(),
this.options, true);
applyTimestampsToChildren(this);
next();
}
The above function was used with getUpdate in schema.js. Please help me out with this issue.
:: SCHEMA ::
const assetListSchema = new Schema({userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
name: String,
config: {
showAssetsLibrary: {
type: Boolean,
required: true,
default: true
},
showAssetsDetails: {
type: Boolean,
required: true,
default: true
},
aliasName: {
type: String,
maxlength: 75,
default: ""
}
}},{ timestamps: true});
:: UPDATE function ::
assetListSchema.methods.update = async function (data) {
try {
let asst = this;
data = _.pick(data, ['showAssetsLibrary',
'showAssetsDetails','aliasName']);
if (_.isEmpty(data)) {
emptyError();
}
return await AssetsHierarchy.findByIdAndUpdate(asst._id, {
config: data
}, {
new: true,
fields: {
"config": 1
}
});
} catch (err) {
throw new Error(err.message);
}
}
:: ERROR ::
TypeError: this.getUpdate is not a function
at model._setTimestampsOnUpdate (D:inspectionAppinspection-backendnode_modulesmongooselibschema.js:873:56)
at callMiddlewareFunction (D:inspectionAppinspection-backendnode_moduleskareemindex.js:427:23)
at next (D:inspectionAppinspection-backendnode_moduleskareemindex.js:58:7)
at Kareem.execPre (D:inspectionAppinspection-backendnode_moduleskareemindex.js:86:8)
at Kareem.wrap (D:inspectionAppinspection-backendnode_moduleskareemindex.js:265:8)
at model.$__update (D:inspectionAppinspection-backendnode_moduleskareemindex.js:339:11)
at utils.promiseOrCallback.callback (D:inspectionAppinspection-backendnode_modulesmongooselibhelpersmodelapplyHooks.js:80:30)
at Promise (D:inspectionAppinspection-backendnode_modulesmongooselibutils.js:246:5)
at new Promise ()
at Object.promiseOrCallback (D:inspectionAppinspection-backendnode_modulesmongooselibutils.js:245:10)
at model.objToDecorate.(anonymous function) [as update] (D:inspectionAppinspection-backendnode_modulesmongooselibhelpersmodelapplyHooks.js:79:20)
at update (D:inspectionAppinspection-backendAppcontrollerssettingsasset-hierarchyassetsHierarchyController.js:163:33)
at Layer.handle [as handle_request] (D:inspectionAppinspection-backendnode_modulesexpresslibrouterlayer.js:95:5)
at next (D:inspectionAppinspection-backendnode_modulesexpresslibrouterroute.js:137:13)
at Route.dispatch (D:inspectionAppinspection-backendnode_modulesexpresslibrouterroute.js:112:3)
at Layer.handle [as handle_request] (D:inspectionAppinspection-backendnode_modulesexpresslibrouterlayer.js:95:5)
javascript mongoose mongoose-schema
When I try to execute the update function I got this error. It happen when I added timestamps: true
I navigate to the error and I got this function called in schema.js in mongoose >> lib folder.
function _setTimestampsOnUpdate(next) {
applyTimestampsToUpdate(createdAt, updatedAt, this.getUpdate(),
this.options, true);
applyTimestampsToChildren(this);
next();
}
The above function was used with getUpdate in schema.js. Please help me out with this issue.
:: SCHEMA ::
const assetListSchema = new Schema({userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
name: String,
config: {
showAssetsLibrary: {
type: Boolean,
required: true,
default: true
},
showAssetsDetails: {
type: Boolean,
required: true,
default: true
},
aliasName: {
type: String,
maxlength: 75,
default: ""
}
}},{ timestamps: true});
:: UPDATE function ::
assetListSchema.methods.update = async function (data) {
try {
let asst = this;
data = _.pick(data, ['showAssetsLibrary',
'showAssetsDetails','aliasName']);
if (_.isEmpty(data)) {
emptyError();
}
return await AssetsHierarchy.findByIdAndUpdate(asst._id, {
config: data
}, {
new: true,
fields: {
"config": 1
}
});
} catch (err) {
throw new Error(err.message);
}
}
:: ERROR ::
TypeError: this.getUpdate is not a function
at model._setTimestampsOnUpdate (D:inspectionAppinspection-backendnode_modulesmongooselibschema.js:873:56)
at callMiddlewareFunction (D:inspectionAppinspection-backendnode_moduleskareemindex.js:427:23)
at next (D:inspectionAppinspection-backendnode_moduleskareemindex.js:58:7)
at Kareem.execPre (D:inspectionAppinspection-backendnode_moduleskareemindex.js:86:8)
at Kareem.wrap (D:inspectionAppinspection-backendnode_moduleskareemindex.js:265:8)
at model.$__update (D:inspectionAppinspection-backendnode_moduleskareemindex.js:339:11)
at utils.promiseOrCallback.callback (D:inspectionAppinspection-backendnode_modulesmongooselibhelpersmodelapplyHooks.js:80:30)
at Promise (D:inspectionAppinspection-backendnode_modulesmongooselibutils.js:246:5)
at new Promise ()
at Object.promiseOrCallback (D:inspectionAppinspection-backendnode_modulesmongooselibutils.js:245:10)
at model.objToDecorate.(anonymous function) [as update] (D:inspectionAppinspection-backendnode_modulesmongooselibhelpersmodelapplyHooks.js:79:20)
at update (D:inspectionAppinspection-backendAppcontrollerssettingsasset-hierarchyassetsHierarchyController.js:163:33)
at Layer.handle [as handle_request] (D:inspectionAppinspection-backendnode_modulesexpresslibrouterlayer.js:95:5)
at next (D:inspectionAppinspection-backendnode_modulesexpresslibrouterroute.js:137:13)
at Route.dispatch (D:inspectionAppinspection-backendnode_modulesexpresslibrouterroute.js:112:3)
at Layer.handle [as handle_request] (D:inspectionAppinspection-backendnode_modulesexpresslibrouterlayer.js:95:5)
javascript mongoose mongoose-schema
javascript mongoose mongoose-schema
edited Nov 13 '18 at 4:52
asked Nov 12 '18 at 14:09
Shailesh Jha
11
11
It's more than likely a problem with your code and not mongoose itself
– kemotoe
Nov 12 '18 at 14:14
Please share yourschemacode
– Mosius
Nov 12 '18 at 14:14
const assetListSchema = new Schema({ userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, name: String, config: { showAssetsLibrary: { type: Boolean, required: true, default: true }, showAssetsDetails: { type: Boolean, required: true, default: true }, aliasName: { type: String, maxlength: 75, default: "" } } }, { timestamps: true });
– Shailesh Jha
Nov 13 '18 at 4:41
assetListSchema.methods.update = async function (data) { try { let asst = this; data = .pick(data, ['showAssetsLibrary', 'showAssetsDetails', 'aliasName']); if (.isEmpty(data)) { emptyError(); } return await AssetsHierarchy.findByIdAndUpdate(asst._id, { config: data }, { new: true, fields: { "config": 1 } }); } catch (err) { throw new Error(err.message); } }
– Shailesh Jha
Nov 13 '18 at 4:43
add a comment |
It's more than likely a problem with your code and not mongoose itself
– kemotoe
Nov 12 '18 at 14:14
Please share yourschemacode
– Mosius
Nov 12 '18 at 14:14
const assetListSchema = new Schema({ userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, name: String, config: { showAssetsLibrary: { type: Boolean, required: true, default: true }, showAssetsDetails: { type: Boolean, required: true, default: true }, aliasName: { type: String, maxlength: 75, default: "" } } }, { timestamps: true });
– Shailesh Jha
Nov 13 '18 at 4:41
assetListSchema.methods.update = async function (data) { try { let asst = this; data = .pick(data, ['showAssetsLibrary', 'showAssetsDetails', 'aliasName']); if (.isEmpty(data)) { emptyError(); } return await AssetsHierarchy.findByIdAndUpdate(asst._id, { config: data }, { new: true, fields: { "config": 1 } }); } catch (err) { throw new Error(err.message); } }
– Shailesh Jha
Nov 13 '18 at 4:43
It's more than likely a problem with your code and not mongoose itself
– kemotoe
Nov 12 '18 at 14:14
It's more than likely a problem with your code and not mongoose itself
– kemotoe
Nov 12 '18 at 14:14
Please share your
schema code– Mosius
Nov 12 '18 at 14:14
Please share your
schema code– Mosius
Nov 12 '18 at 14:14
const assetListSchema = new Schema({ userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, name: String, config: { showAssetsLibrary: { type: Boolean, required: true, default: true }, showAssetsDetails: { type: Boolean, required: true, default: true }, aliasName: { type: String, maxlength: 75, default: "" } } }, { timestamps: true });
– Shailesh Jha
Nov 13 '18 at 4:41
const assetListSchema = new Schema({ userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, name: String, config: { showAssetsLibrary: { type: Boolean, required: true, default: true }, showAssetsDetails: { type: Boolean, required: true, default: true }, aliasName: { type: String, maxlength: 75, default: "" } } }, { timestamps: true });
– Shailesh Jha
Nov 13 '18 at 4:41
assetListSchema.methods.update = async function (data) { try { let asst = this; data = .pick(data, ['showAssetsLibrary', 'showAssetsDetails', 'aliasName']); if (.isEmpty(data)) { emptyError(); } return await AssetsHierarchy.findByIdAndUpdate(asst._id, { config: data }, { new: true, fields: { "config": 1 } }); } catch (err) { throw new Error(err.message); } }
– Shailesh Jha
Nov 13 '18 at 4:43
assetListSchema.methods.update = async function (data) { try { let asst = this; data = .pick(data, ['showAssetsLibrary', 'showAssetsDetails', 'aliasName']); if (.isEmpty(data)) { emptyError(); } return await AssetsHierarchy.findByIdAndUpdate(asst._id, { config: data }, { new: true, fields: { "config": 1 } }); } catch (err) { throw new Error(err.message); } }
– Shailesh Jha
Nov 13 '18 at 4:43
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263904%2fmongoose-5-3-this-getupdate-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263904%2fmongoose-5-3-this-getupdate-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's more than likely a problem with your code and not mongoose itself
– kemotoe
Nov 12 '18 at 14:14
Please share your
schemacode– Mosius
Nov 12 '18 at 14:14
const assetListSchema = new Schema({ userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, name: String, config: { showAssetsLibrary: { type: Boolean, required: true, default: true }, showAssetsDetails: { type: Boolean, required: true, default: true }, aliasName: { type: String, maxlength: 75, default: "" } } }, { timestamps: true });
– Shailesh Jha
Nov 13 '18 at 4:41
assetListSchema.methods.update = async function (data) { try { let asst = this; data = .pick(data, ['showAssetsLibrary', 'showAssetsDetails', 'aliasName']); if (.isEmpty(data)) { emptyError(); } return await AssetsHierarchy.findByIdAndUpdate(asst._id, { config: data }, { new: true, fields: { "config": 1 } }); } catch (err) { throw new Error(err.message); } }
– Shailesh Jha
Nov 13 '18 at 4:43