-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add maxTime option to all queries #4066
Comments
Write a plugin, use query middleware |
Hi @vkarpov15 , So it looks like this option is working, am I wrong? |
@tomgrossman yep should be working, just added it to the docs. |
@vkarpov15 So there is no need for a plugin, right? Should be closed. |
I think the original issue was "ability to set maxTimeMS for all queries" which is a task for a plugin. Adding the option to the docs is separate. |
@vkarpov15 sorry I don't understand. I said before that this option already exists but was only missing in the docs. So there is no need for a plugin. Am I wrong? |
The plugin is for setting max time ms for all queries at once, like |
@vkarpov15 no, the original case was the option to add this timeout for every query. as an option. |
Ok then we can close this issue :) |
Hey just to know, |
@santimendoza the option is maxTimeMS http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#findOne we will add it to the mongoose docs |
@vkarpov15 I was just looking to do this - would the plugin approach still be the best way to achieve global query timeouts in latest mongoose v5? |
bump @vkarpov15 I was just looking to do this - would the plugin approach still be the best way to achieve global query timeouts in latest mongoose v5? |
@freewil yes it would. I'm going to be writing a blog post on maxTimeMS next week that you should keep an eye out for. MaxTimeMS has some caveats |
@vkarpov15 Hi! |
@natanavra can you write a script that demonstrates this issue and clarify which version of Mongoose you're using? Here's the |
@vkarpov15 using Mongoose 5.0.16 Here's an example: return await model
.find(query, null)
.sort(sort)
.maxTime(constants.maxQueryMS) //maxTimeMS here does not work
.hint(model.getHint())
.limit(constants.maxEvents)
.cache(10)
.catch(err => {
logger.warn({err}, 'events.find failed');
}); |
@natanavra You can't use that in mongoose 5.0.16. It was added in mongoose 5.2.6 I added maxTimeMS alias to maxTime in mquery v3.1.1, an underlying library of mongoose. This was introduced since [email protected], which used this version of mquery. mongoosejs/mquery#105 For those who uses TypeScript, my PR for Query#maxTimeMS is awaiting to be merged DefinitelyTyped/DefinitelyTyped#35677 and will be released as @types/[email protected] |
@Fonger Ahh thanks for letting me know |
I can't find maxTimeMSPlugin, so is this just an example? @vkarpov15 |
@GeniusBrother we added a global and connection level mongoose.set('maxTimeMS', 3000); Or: const db = mongoose.createConnection(uri);
db.set('maxTimeMS', 3000); |
See |
I would like to add the option for maxTime(ms) for all models queries (find, update, findOneAndUpdate, etc..).
for example:
A.findOneAndUpdate(id, updateObject, {maxTime: 1000}}, callback)
The text was updated successfully, but these errors were encountered: