2

I have a Mongoose Schema which contains a field with a certain index:

const reportSchema = new mongoose.Schema({
    coords: {
    type: [Number],
    required: true,
    index: '2dsphere'
    },
…
}

It works well on my local machine, so when I connect to MongoDB through the shell I get this output for db.reports.getIndexes():

[
{
    "v" : 2,
    "key" : {
        "_id" : 1
    },
    "name" : "_id_",
    "ns" : "weatherApp.reports"
},
{
    "v" : 2,
    "key" : {
        "coords" : "2dsphere"
    },
    "name" : "coords_2dsphere",
    "ns" : "weatherApp.reports",
    "background" : true,
    "2dsphereIndexVersion" : 3
}
]

Then I deploy this app to Heroku and connect to MongoDB Atlas instead of my local database. It works well for saving and retrieving data, but did not create indexes (only default one):

[
{
    "v" : 2,
    "key" : {
        "_id" : 1
    },
    "name" : "_id_",
    "ns" : "weatherApp.reports"
}
]

What may cause this problem? Atlas allow to create indexes through Web GUI and it works good as well as creating indexes form the shell. But Mongoose fails this operation for some reason.

5
  • can you check atlas logs ? Also, you automigrate your data ? after inserting data the index still not there ? Commented Oct 5, 2018 at 13:33
  • @anouarKacem, no, after inserting data there's still no index. Tried to check the logs on Atlas, but actually couldn't figure out where to get an access to them. Commented Oct 5, 2018 at 14:22
  • @MishaGoncharov did you ever find out what the issue was? Commented Oct 25, 2018 at 3:33
  • @Joseph, unfortunately, no. Atlas Support didn't help as well :-( Commented Oct 25, 2018 at 8:49
  • @MishaGoncharov I just figured out what was wrong for me. I'll submit an answer. Commented Oct 25, 2018 at 11:39

1 Answer 1

2

I had the same issue when I was on mongoose version v5.0.16. However, since I updated to v5.3.6 it is now creating the (compound) indexes for me on Mongo Atlas. (I just wrote a sample app with both versions to verify this is the case).

I'm not sure which version fixed this issue, but it's somewhere between v5.0.16 and v5.3.6, where v5.3.6 is working.

Sign up to request clarification or add additional context in comments.

3 Comments

Wow, I use 5.2.13. Gonna update it and check it out, thank you
Yes, it helped!
@MishaGoncharov glad to hear it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.