Since I couldn't get this resolved in the the mongo store module, I've tried the
exact same implementation with the express-brute-mongoose store, and encountered
the same error. Since the error gets triggered in express-brute, I'm hoping to find answers here on how to resolve this.
This is the middleware I set up (same as defaults, but logging the dup key error):
var rateLimitMiddleware = new ExpressBrute(bruteStore, {
failCallback: function (req, res, next, nextValidRequestDate) {
var err = new Error('Too many attempts.');
err.status = 429;
next(err);
},
handleStoreError: function (error) {
console.log(error);
}
});
My implementation with express-brute-mongo was:
var MongoStore = require('express-brute-mongo');
var MongoClient = require('mongodb').MongoClient;
var bruteStore = new MongoStore(function (ready) {
MongoClient.connect(process.env['DB_URL'], function (err, db) {
if (err) throw err;
db.collection('ratelimits').ensureIndex({expires: 1}, {expireAfterSeconds: 0});
ready(db.collection('ratelimits'));
});
});
My implementation with express-brute-mongoose is:
var MongooseStore = require('express-brute-mongoose');
var BruteForceSchema = require('express-brute-mongoose/dist/schema');
var bruteModel = mongoose.model('bruteforce', BruteForceSchema);
var bruteStore = new MongooseStore(bruteModel);
Any help why i'm hitting dup key MongoErrors would be greatly appreciated.
I was working with the express-brute-mongo store, and encountered this error:
Since I couldn't get this resolved in the the mongo store module, I've tried the exact same implementation with the express-brute-mongoose store, and encountered the same error. Since the error gets triggered in express-brute, I'm hoping to find answers here on how to resolve this.
This is the middleware I set up (same as defaults, but logging the dup key error):
My implementation with express-brute-mongo was:
My implementation with express-brute-mongoose is:
Any help why i'm hitting dup key MongoErrors would be greatly appreciated.