I was reading about ReDOS. https://en.wikipedia.org/wiki/ReDoS
It seems if you run this code in Node.js:
console.time('aaa');
/^(a+)+$/.test('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!')
console.timeEnd('aaa');
it takes around 7821ms to run.
But if I add the same value to MongoDB:
db.users.insert({name: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!"});
db.users.findOne({name: { '$regex': '^(a+)+$'}});
This gets evaluated immediately and it returns null.
Any idea how MongoDB is able to evaluate it so fast?