-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[QUESTION] user is not allowed to do action [createIndex] on [db.system.indexes] #6976
Comments
@kimmanwky I believe this was fixed in a past update. Can you update to mongoose@latest and try again? Be aware that with the newest version, you'll need to deal with some deprecation warnings as detailed here and index creation failing with A simple example: 6976.js#!/usr/bin/env node
'use strict';
const { ATLASSRV } = require('/Users/lineus/.env');
const mongoose = require('mongoose');
let uri;
let opts = {};
if (mongoose.version === '5.2.13') {
opts.useNewUrlParser = true;
mongoose.set('useCreateIndex', true);
uri = ATLASSRV.replace('?retryWrites=true', '');
} else {
console.log(`running mongoose: ${mongoose.version}`);
uri = ATLASSRV;
}
mongoose.connect(uri, opts);
const conn = mongoose.connection;
const Schema = mongoose.Schema;
const schema = new Schema({ name: { type: String, unique: true } });
const Test = mongoose.model('Test', schema);
async function run() {
await conn.dropDatabase();
await Test.init();
console.log(`it works in mongoose: ${mongoose.version}`);
return conn.close();
}
run(); Output with 5.1.8
Output with 5.2.13 (mongoose@latest)
|
As a workaround, you can also use the |
Let us know if this is still an issue for you @kimmanwky, closing this for now. |
@kimmanwky did you ever resolve your issue? I have been trying to resolve this for hours. |
@SabrinaDanielle I'm afraid I not quite remember how do I fix it. Perhaps, you could try by adding additional options for your MongoDB connection?
|
I'm working on project in node.js + express with mongoose, connected to Mongodb Atlas (free sandbox).
Using:
"mongoose": "^5.1.8",
With user model schema as below:
username: { type: Types.String, required: true, unique: true },
I hit this error when connecting to mongodb altas sandbox server.
MongoError: user is not allowed to do action [createIndex] on [tp2fa.system.indexes]
Based on my research, mongodb altas doesnt not allow user to createindex at db.system, and indexes should be created on collection [db.collection.indexes].
Is this a bug or there is a way for us to create indexes on specific collection to avoid such error when using mongodb altas?
Note:
The user that used to connect to mongodb altas is Altas Admin (full permission)
Reference:
The text was updated successfully, but these errors were encountered: