I'm using GridFsTemplate to store files on mongoDB, but when I do a search I get the error "The index path corresponding to the specified order-by item is excluded"
In local this works fine but not in Cosmos DB.
Example of my code
@Autowired
private GridFsTemplate fsTemplate;
.....
.....
....
GridFSFile f= fsTemplate.findOne(new Query(Criteria.where("filename").is(filename))); <----- Error in this line only in cosmos db (azure)
By default the collection fs.files has two index => _id (unique, regular) , filename uploadDate (compound , regular)
I test it in the Open Mongo Shell and I'm getting the same error
db.fs.files.find({"filename":"filename"}).sort({"filename":1})
Error: error: {
"ok" : 0,
"errmsg" : "Error=2, Details='Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: b65fca6d-ef9a-4966-83cf-b7f4f7a263b1; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: b65fca6d-ef9a-4966-83cf-b7f4f7a263b1; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: b65fca6d-ef9a-4966-83cf-b7f4f7a263b1; Reason: (Message: {\"Errors\":[\"The order by query does not have a corresponding composite index that it can be served from.\"]}\r\nActivityId: b65fca6d-ef9a-4966-83cf-b7f4f7a263b1, Request URI: /apps/950b32f2-6902-4b2e-9311-eca73a7e886f/services/d42e30e2-ff77-4a04-a474-2fce0e42fcb2/partitions/39edd886-7a4b-40a2-9c59-377ce7d13dd6/replicas/132640599096005533s/, RequestStats: Please see CosmosDiagnostics, SDK: Windows/10.0.17763 cosmos-netstandard-sdk/3.3.2);););",
"code" : 2,
"codeName" : "BadValue"
}
globaldb:PRIMARY> db.fs.files.find({"filename":"filename"}).sort({"filename":1}).count()
1
best regards