I have a Spring project in Java that accesses the Mongo database with Spring Query Methods along with some custom queries that use MongoTemplate.
Once I switched and connected to the CosmosDB, a few of my queries don’t work anymore while others do.
For example, the Spring query method findAllByOrderByValueAsc()
used to work with MongoDB, but now it does not and returns the BadValue error.
However, findAll()
from the Spring query methods works. And also this MongoTemplate-utilizing query works for both too:
public List<String> findDistinctLanguageByKeyOrderByLanguageAsc(String key) {
Query query = new Query();
query.addCriteria(new Criteria("key").is(key));
return mongoTemplate.findDistinct(query, "language", User.class, String.class);
}
I am trying to rewrite some of my Spring query methods to just use MongoTemplate, but this will give the same error as well (which is directly from https://www.baeldung.com/queries-in-spring-data-mongodb):
Query query = new Query();
query.with(Sort.by(Sort.Direction.ASC, "language"));
List<User> users = mongoTemplate.find(query, User.class);
I didn’t change anything when moving from Mongo to Cosmos other than my application.properties. What resource should I be looking at in order to see what queries are available in MongoTemplate and CosmosDB? Or is there another way to query CosmosDB where I don’t have to rewrite all of my code for Mongo?