I am using Mongoose with a very large Mongo database, and I want costly queries like MySet.find({})
to time out after 10 seconds.
I've tried setting a socket timeout on my connection, but the server crashes if the timeout is exceeded:
var options = {server: {socketOptions: {socketTimeoutMS: 10000}}};
var conn = mongoose.connect('mongodb://localhost/my_db', options);
I've tried passing the maxTimeMS option to the find function, but that doesn't have any effect at all:
MySet.find({}, {}, {timeout: true, maxTimeMS: 10000}, function(err, doc) {});
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…