Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library attempts to create indexes #15

Closed
gregorskii opened this issue May 19, 2020 · 10 comments
Closed

Library attempts to create indexes #15

gregorskii opened this issue May 19, 2020 · 10 comments

Comments

@gregorskii
Copy link

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

@okv
Copy link
Contributor

okv commented May 19, 2020

Hi, I got your point.
I'll try to check current behavior and possible solution (I have a couple of ideas) soon.

@gregorskii
Copy link
Author

Awesome thank you!

@okv
Copy link
Contributor

okv commented May 20, 2020

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, [email protected]).

@gregorskii could you help me with that? What error do you have? Do you have any thoughts about why did it happen?

@gregorskii
Copy link
Author

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.

@okv
Copy link
Contributor

okv commented May 20, 2020

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.

@gregorskii
Copy link
Author

Yep, enabled by default, but removed if defined would be great. Thanks so much!

@okv okv closed this as completed in c3f7f1c May 22, 2020
@okv
Copy link
Contributor

okv commented May 22, 2020

Implemented and published to npm as [email protected]
@gregorskii could you check it against your expectations?)

@gregorskii
Copy link
Author

Looks great! Thanks!

@jaankoppe
Copy link

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!

@okv
Copy link
Contributor

okv commented Jan 10, 2021

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?

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

No branches or pull requests

3 participants