I have a mongodb collection with several documents of the following structure
{
"_id" : "...",
"_class" : "...",
...
"travelers" : [
{
"id": "12345",
"type": "XYZ"
},
{
"id": "67890",
"type": "ABC"
}],
...
}
Using spring data, I can get documents that have the XYZ traveler type:
Query query = new Query(Criteria.where("travelers.type").is("XYZ");
List<Something> something = mongoTemplate.find(query, Something.class, COLLECTION_NAME);
But if I switch the select query with the traveler ID, I get no results:
Query query = new Query(Criteria.where("travelers.id").is("12345");
List<Something> something = mongoTemplate.find(query, Something.class, COLLECTION_NAME);
I turned on all the logs, and the outgoing request {"travelers.id" : "12345"}looks correct. Running a query {"travelers.id" : "12345"}directly on db returns the correct results.
The other queries I tried in the collection work fine. I tried both with the index and without it on travel.id and no results in both cases. What am I doing wrong?
source
share