I’m having a very strange issue, and I suspect that I must be missing something obvious, but I can’t figure out what.
I’m running 5.0.15 in a Docker Desktop k8s cluster, and I can store and retrieve data as expected. However, there are no indexes defined (I’m using Spring Data’s @Indexed annotation). At first I thought that there might be a Spring issue, but I finally tried in mongosh, and I can’t create indexes there, so I think that’s the main problem.
When I run this in mongosh:
obiwan-rest> db.company.getIndexes();
[ { v: 2, key: { _id: 1 }, name: '_id_' } ]
obiwan-rest> db.customer.createIndex({"customerNumber":1},{unique:true});
customerNumber_1
obiwan-rest> db.company.getIndexes();
[ { v: 2, key: { _id: 1 }, name: '_id_' } ]
it seems that createIndex() succeeded, but the created index is not shown. In Compass, I can’t see it either.
When I create the same index in Compass, it does show up. And if I try to create a similar index, for example, by leaving out the unique option, I do get an error message:
obiwan-rest> db.company.getIndexes();
[ { v: 2, key: { _id: 1 }, name: '_id_' } ]
obiwan-rest> db.customer.createIndex({"customerNumber":1});
MongoServerError: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { v: 2, key: { customerNumber: 1 }, name: "customerNumber_1" }, existing index: { v: 2, unique: true, key: { customerNumber: 1 }, name: "customerNumber_1" }
I’m not sure what’s happening here. Is there something missing on the server side? Am I using createIndex() wrong?
The collection has one document in it, so I would expect index creation to be instantaneous. But even waiting 10 minutes does not make the index show up, so I don’t think it’s anything to do with background index creation.