Reputation: 79
I'm trying to figure out if there's a way to apply a query timeout in the script file
of MongoDB to prevent slow/idle/hanging requests.
I am referring https://docs.mongodb.com/manual/reference/method/cursor.maxTimeMS/#examples documentation.
Now I am trying to write script as below for the maxTimeMS
as below:-
#!/bin/bash
db.collection.find({ $query: {}, $maxTimeMS: 100 })
And it is giving an error:-
mongodb-timeout.sh: line 4: syntax error near unexpected token `{'
mongodb-timeout.sh: line 4: `db.collection.find({ $query: {}, $maxTimeMS: 100 })'
Does anybody have an idea? Thanks in advance
Upvotes: 0
Views: 1244
Reputation: 523
What you probably need, is mongodb Node.js driver documentation. There is an option to set a timeout for particular query (i.e. cursor).
cursor.maxTimeMS is a Mongo shell method which is different from Node.js (though both of them are javascript based).
Upvotes: 0
Reputation: 490
I think maxTimeMS is the curser option, not a system-wide variable. As you can see in their jira you might be able to write some script to achieve this.
Upvotes: 0