2

I am creating a program to list nearby objects based on the user's current location.

For this I am using the old [longitude, latitude] system. I will store these coordinates in the location field.

The following error shows up when I try to create a 2d index::

MongoError: user is not allowed to do action [createIndex] on [data.system.indexes]

However, I am dbAdmin hence I have all permission to create and drop indexes.

My code::

const uri = "mongodb:// <link with password and dbname>"
const MongoClient = require("mongodb").MongoClient;

function connect(){
    MongoClient.connect(uri, {useNewUrlParser: true}, (err, client)=>{
        if(err) throw err;
        else{
            const db = client.db(dbname);

            db.collection("collection").createIndex({"location": "2d"})
        }
    });
}

Also, please don't close this question as duplicate; in this case, the user is not the problem (since I am admin) and neither have I mixed up the password.

I can create text indexes just fine and am able to do stuff like dropping indexes and dropping the entire db so surely I can create the 2d index?

Thanks!

Jay John
  • 21
  • 3
  • What version of mongo are you using? @Jay John – razki Apr 01 '19 at 20:56
  • I'm not able to reproduce the error you're seeing with this code. The error suggests some part of your app is attempting to create an index on `system.indexes` instead of on `collection`. Does any part of your code attempt to access that collection? – Adam Harrison Apr 01 '19 at 21:58
  • Actually, all of the work is being done only on collection 'collection'. Does 2d index require other permissions? I am able to make text indexes just fine – Jay John Apr 02 '19 at 05:09
  • @razki 3.2.2 - latest version – Jay John Apr 02 '19 at 05:39
  • I was testing on MongoDB Atlas on a dev sandbox cluster when I got this error. Interestingly, I deleted all but one document (given that it was a test cluster) and I was able to create the index. No clue why. – arao6 Oct 10 '19 at 00:10

0 Answers0