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
6.9.1
Node.js version
19.5.0
MongoDB server version
6.0.4
Typescript version (if applicable)
No response
Description
Hi. When bulkSave() is called, it fires post save middleware, but for some reason, the doc parameter is a function, but typings indicate it should be a document. Using this works tho.
Apart from that, what is the proper way to get a document? Docs list these 2 ways, but I couldn't find the difference between them in the docs.
Steps to Reproduce
importmongoosefrom"mongoose";mongoose.set("debug",true);awaitmongoose.connect("mongodb://127.0.0.1:27017/mongooseissue");constschema=newmongoose.Schema({foo: Boolean,bar: Boolean});schema.post("save",function(doc){// 'doc' is typed as:// mongoose.Document<unknown, any, { foo?: boolean | undefined; bar?: boolean | undefined; }> & { foo?: boolean | undefined; bar?: boolean | undefined; } & { _id: mongoose.Types.ObjectId; }console.log("this:");console.log(this);console.log("doc:");console.log(doc);})constTestModel=mongoose.model("test",schema);asyncfunctionone(){constdoc=newTestModel({foo: true,bar: true});awaitdoc.save();// 'this' and 'doc' are printed in post middleware, they're equal}asyncfunctiontwo(){constdocs=awaitTestModel.find({}).exec();docs.forEach(doc=>{doc.foo=false;})awaitTestModel.bulkSave(docs);// 'this' is a document// 'doc' parameter is a function, why?}console.log("One");awaitone();console.log("Two");awaittwo();
Expected Behavior
The doc parameter is a document
The text was updated successfully, but these errors were encountered:
Prerequisites
Mongoose version
6.9.1
Node.js version
19.5.0
MongoDB server version
6.0.4
Typescript version (if applicable)
No response
Description
Hi. When
bulkSave()
is called, it fires post save middleware, but for some reason, thedoc
parameter is a function, but typings indicate it should be a document. Usingthis
works tho.Apart from that, what is the proper way to get a document? Docs list these 2 ways, but I couldn't find the difference between them in the docs.
Steps to Reproduce
Expected Behavior
The
doc
parameter is a documentThe text was updated successfully, but these errors were encountered: