question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property '_update' of undefined

See original GitHub issue

Do you want to request a feature or report a bug? BUG

What is the current behavior? TypeError: Cannot read property ‘_update’ of undefined

If the current behavior is a bug, please provide the steps to reproduce. Here’s a sample of code to reproduce the bug

const mongoose = require("mongoose");

const exampleSchema = new mongoose.Schema({
	name: { type: String },
	value: { type: Number },
}, {
	collection: "example",
	strict: "throw",
});
const ExampleModel = mongoose.model("Model", exampleSchema);
const example = new ExampleModel({ name: "example 1", value: 1 });

return mongoose
	.connect('mongodb://localhost:27017/test', {
		useNewUrlParser: true, useUnifiedTopology: true
	})
	.then(() => example.save())
	.then(() => ExampleModel.findOneAndUpdate({
			name: "example 1",
		} , {
			$set: { value: 2 },
		}, {
			runValidators: true,
		})
		.select("value")
	)
	.then((result) => console.log("test OK", result))
	.finally(() => mongoose.disconnect())
	.catch((error) => console.log("ERROR", error.stack));

What is the expected behavior? we expected the document to be updated

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version.

  • node : 10.16.0
  • mongoose : 5.7.0
  • mongoDb: 3.6.12

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

2reactions
baubletcommented, Sep 11, 2019

@kevin-wynn and I just spent all day debugging this. Apparently there an API breaking change in several hooks (in our case, in a pre hook) between 5.6 and 5.7. To fix this, lock your version numbers tightly. We we locked our to an older version:

"mongoose": "^5.2.18",
"mongoose": "5.2.x",

// OR

"mongoose": "5.2.18",

Or, if the above comments are correct about 5.6.13:

"mongoose": "5.6.13",

For reference (and for Google to help find this), here’s the stack trace we got from 5.7.0:

TypeError: Cannot read property '_update' of undefined
    at node_modules/mongoose/lib/query.js:3546:58
    at node_modules/mongoose/lib/utils.js:264:16
    at _done (node_modules/mongoose/lib/helpers/updateValidators.js:253:5)
    at node_modules/mongoose/lib/helpers/updateValidators.js:223:11
    at schemaPath.doValidate.updateValidator (node_modules/mongoose/lib/helpers/updateValidators.js:164:13)
    at node_modules/mongoose/lib/schematype.js:1029:11
    at node_modules/async-listener/glue.js:188:31
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:219:9)
0reactions
sergebessoncommented, Sep 19, 2019

I confirm that version 5.7.1 fix the issue. thank you very much 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property 'update' of undefined - Stack Overflow
When you're creating a new Chest object, you have to use the new operator. So in this code: // Create 4 chests on...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError: Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an undefined...
Read more >
TypeError: Cannot read property 'update' of undefined #254
It seems that this.popperInstance is not defined in _setContent . I had a quick look at ensureShown function and I don't understand why...
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
The Cannot read property xxx of undefined error is one such example. In particular, the Cannot read property 'n' of undefined (where n...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found