I am using Spring Data and Mongo Driver 2.10.0 .
Here is the data , I was querying on
{ "_id": { "$oid" : "50bfc7218df4decc94d2815d" },
"_class": "xyz",
"tokenList": [ { "_id": asdfhfg,
"description": "Sample token 2",
"name": "DRAK",
"parentCategoryId": "abc" },
{ "_id": jdsfhdsjf,
"description": "Sample token2",
"name": "DRAK2",
"parentCategoryId": "abc"
}
],
"name": "test"
}
Here is how the query was defined using Spring Data, to retrieve a specific sub-document from this array "tokenList".
@Query(value = "{ '_id' : ?0 }", fields = "{'tokenList' : {$elemMatch : {'name' : ?1}}}")
List<Token> getToken(String id, String tokenName);I am getting the error "com.mongodb.MongoException: Unsupported projection option: $elemMatch" from the Monogo driver,
and after debugging further, the actual error message that is being returned from Mongo is { "$err" : "Unsupported projection option: $elemMatch" , "code" : 13097} to the Java driver.But If I run the same query using Mongo SHell, it runs fine with the expected result. i.e.
db.token.find({ "_id" : ObjectId("50b7330279e881b8a010c84e")}, { "tokenList" : {$elemMatch : {"name" : "BRAK"}}})
returns , the sub-document from the list and the _id of the top level document.
{ "_id": asdfhfg,
"description": "Sample token 2",
"name": "DRAK",
"parentCategoryId": "abc" },Any insight into what I may be doing wrong would be quite helpful.
Thanks