You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.10.1
Node.js version
18.19.1
MongoDB server version
6.13.0
Typescript version (if applicable)
5.3.3
Description
I'm trying to update Mongoose from 7.6.8 to 8.10.1. I tested it on my staging server and got a strange error.
{
"name": "TypeError",
"message": "Cannot read properties of undefined (reading 'now')",
"stack": "TypeError: Cannot read properties of undefined (reading 'now')\n at setDocumentTimestamps (/tracer/node_modules/mongoose/lib/helpers/timestamps/setDocumentTimestamps.js:9:41)\n at EmbeddedDocument.timestampsPreSave (/tracer/node_modules/mongoose/lib/helpers/timestamps/setupTimestamps.js:51:5)\n at callMiddlewareFunction (/tracer/node_modules/kareem/index.js:628:27)\n at EmbeddedDocument.next (/tracer/node_modules/kareem/index.js:93:7)\n at _next (/tracer/node_modules/kareem/index.js:146:10)\n at /tracer/node_modules/kareem/index.js:653:30\n at processTicksAndRejections (node:internal/process/task_queues:77:11)"
}
Without a repro script, we're unlikely to be able to fix this. base is the Mongoose instance associated with the document's model constructor, so if base is undefined then .constructor might not be a Mongoose model.
Can you please modify the following script to demonstrate the issue you're seeing? The following script executes with no errors.
constmongoose=require('mongoose');constconnectionString='mongodb://localhost:27017/testdb';constNestedSchema=newmongoose.Schema({name: String},{timestamps: true});constParentSchema=newmongoose.Schema({nested: NestedSchema});constParentModel=mongoose.model('Parent',ParentSchema);asyncfunctionrun(){awaitmongoose.connect(connectionString);// Create a documentconstdoc=awaitParentModel.create({nested: {name: 'before'}});console.log('Created:',doc);// Update the nested documentdoc.nested.set({name: 'after'});awaitdoc.save();// This should trigger the error}run();
Prerequisites
Mongoose version
8.10.1
Node.js version
18.19.1
MongoDB server version
6.13.0
Typescript version (if applicable)
5.3.3
Description
I'm trying to update Mongoose from 7.6.8 to 8.10.1. I tested it on my staging server and got a strange error.
I went to the problematic code and found this.
As I commented above, base.now is undefined. Could you fix it?
Steps to Reproduce
I tested it on my staging environment as already mentioned.
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: