Cosmos DB - Spring Data - Find By Collection Contains

Viewed 780

I have an entity as follows:

@Document(collection = "MetadataMerchants")
public class MetadataMerchant {

        public String id;

        @PartitionKey
        public String name;

        @JsonProperty("descriptors")
        public List<String> descriptors;
}

and my Repository is as follows:

@Repository
public interface MetadataMerchantRepository extends CosmosRepository<MetadataMerchant, String> {

    List<MetadataMerchant> findByName(String name);

    List<MetadataMerchant> findByDescriptorsContains(List<String> descriptors);
}

findByName is working as expected, in other words this returns a single result:

repository.findByName("Test Merchant");

I want to be able to query MetadataMerchants that has a specific descriptor. My attempt with findByDescriptorsContains(List<String> descriptors) does not seem to be working, it always returns an empty result.

Using spring-data-cosmosdb and Spring Data, how do I query entities by values in a collection? I want to be able to find all MetadataMerchants with descriptors containing a specific value..

In Azure Cosmos DB Data Explorer, the following query works:

SELECT * FROM MetadataMerchants m WHERE EXISTS(SELECT VALUE d FROM d IN m.descriptors WHERE d = 'a-descriptor-here')

I stole the idea from MongoDB examples (see List<Person> findBySkillsContains(List<String> skills);)

0 Answers
Related