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!