Closed gregorskii closed 4 years ago
Hi, I got your point. I'll try to check current behavior and possible solution (I have a couple of ideas) soon.
Awesome thank you!
I'm trying to reproduce the error but no luck currently - createIndex
considered to be idempotent operation and works as expected:
const {MongoClient} = require('mongodb');
const main = async () => {
const url = 'mongodb://localhost:27017/test';
const client = new MongoClient(url);
await client.connect();
const db = client.db();
await db.collection('testIndexes').createIndex(
{expirationDate: 1},
{expireAfterSeconds: 0}
);
await db.collection('testIndexes').createIndex(
{expirationDate: 1},
{expireAfterSeconds: 0}
);
};
main()
.then(() => {
console.log('All done');
})
.catch((err) => {
console.error('Error occurred: ', err.stack || err);
});
I get "All done" output (nodejs 10.x, mongodb@3.5.7).
@gregorskii could you help me with that? What error do you have? Do you have any thoughts about why did it happen?
It says the user does not have the necessary permissions to add the indexes. I have added a custom role to mongo atlas with the ability to create indexes but it’s not working.
My point though is that I don’t think the code necessarily needs the ability to create the index it just needs to be able to write. I can add the index manually.
Shouldn’t it be optional that it creates them? Or that you can optionally not create them.
I wanted to fully understand the situation to provide reasonable solution.
Ok, I agree, since craeteIndex
may fail due to permission issues (e.g. with atlas) it looks reasonable to me to add option to create an index (will be enabled by default).
I'll implement it.
Yep, enabled by default, but removed if defined would be great. Thanks so much!
Implemented and published to npm as rate-limit-mongo@2.2.0 @gregorskii could you check it against your expectations?)
Looks great! Thanks!
Hey!
Having the same issue, when setting the option createTtlIndex to false, then I will get the following error:
MongoError: user is not allowed to do action [find] on [<dbname>.expressRateRecords]
before it was:
MongoError: user is not allowed to do action [createIndex] on [<dbname>.expressRateRecords]
Using Mongo Atlas and have readWrite rights to the user which I am connection to database. readWrite rights has built-in createCollection and createIndex rights.
Any thoughts how to solve this?
Thanks!
Hey @jaankoppe, I don't have a chance to check it out particularly with Mongo Atlas right now but when createTtlIndex
is false
there should not be an index creation call. Are sure that you're using rate limit mongo >= 2.2.0 and createTtlIndex: false
?
Can this be optionally turned off?
The implementor could create the indexes manually if they were detailed in the readme.
This is currently failing for me with Atlas even when the writer has admin permissions, and the index exists. Looking into this more on my end.
Thanks