Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Duplicate key error in collection #16

Open
adriaanmeuris opened this issue Mar 9, 2017 · 1 comment
Open

Duplicate key error in collection #16

adriaanmeuris opened this issue Mar 9, 2017 · 1 comment

Comments

@adriaanmeuris
Copy link

I've set up the module and seems to be working fine, however I'm getting duplicate key errors:
errmsg: 'E11000 duplicate key error collection: mydb.ratelimits index: _id_ dup key: { : "G/IAnx1Agvj9X0JzMvChzHFl6jKU0ps4dnfVvJ+ZYTc=" }' } }

I've ensured the index to be set, this is my implementation:

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'));
  });
});

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);
  }
});

Any ideas?

@adriaanmeuris
Copy link
Author

FYI, this happens when the module tries to increment the request count (error message: "Cannot increment request count")

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant