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
Do you want to request a feature or report a bug?
feature
Requirement Example
When a record is created in Sales table, a middleware is triggered which updates Inventory table. In this middleware, we need access to User to store which user triggered update in Inventory.
How I solve it currently
When the Shop Query is called, a meta object is passed in the options. Then in the middleware, I call query.getOptions() to get this meta object.
Feature Request
Add official support for meta object. Currently, the VS code gives warning that there is NO Meta property which can be passed in the options.
Sample Code
// Model & SchemaconstsalesSchema=newMongoose.Schema({// schema definition});constinventoySchema=newMongoose.Schema({// schema definition});salesSchema.post(['updateOne','findOneAndUpdate'],{document: false,query: true},asyncfunction(){updateInventory(this)});exportconstSales=Mongoose.model('sales',salesSchema);exportconstInventory=Mongoose.model('sales',inventoySchema);
// Middleware functionexportasyncfunction(shopQuery){constmeta=shopQuery.getOptions()?.meta??{}// User is now available in this meta object.const{user}=meta;// Now when I am updating Inventory, I can update the userId field awaitInventory.create({/** other fields */userid: user.id})}
// Sales Update Function constsales=awaitSales.findByIdAndUpdate(id,{ ...req.body},// NOTE: passing user in options which can then be accessed by middleware{new: true,meta: {user:{id:1234}}})
The text was updated successfully, but these errors were encountered:
vkarpov15
added
typescript
Types or Types-test related issue / Pull Request
and removed
new feature
This change adds new functionality, like a new method or class
labels
Sep 7, 2021
Do you want to request a feature or report a bug?
feature
Requirement Example
When a record is created in Sales table, a middleware is triggered which updates Inventory table. In this middleware, we need access to User to store which user triggered update in Inventory.
How I solve it currently
When the Shop Query is called, a meta object is passed in the
options
. Then in the middleware, I callquery.getOptions()
to get this meta object.Feature Request
Add official support for meta object. Currently, the VS code gives warning that there is NO Meta property which can be passed in the options.
Sample Code
The text was updated successfully, but these errors were encountered: