I have a database structure like this:
{
"_id" : "Foo",
"registrations" : [
101,
102
]
}
What I would like to do is create a query that will find all documents that contain a "registrations" array with the value 101 contained within it. I would like to use the QueryBuilder if at all possible because I typically find it easier to use.
Based on this answer, I tried to use elemMatch() to find it, but that didn't seem to have the desired effect:
QueryBuilder.start().put("registrations").elemMatch(new BasicDBObject("_id", 101)).get();
However, the stacktrace said that it is trying to cast the BasicDBObject to an Integer and failing.
java.lang.ClassCastException: java.lang.Integer cannot be cast to com.mongodb.DBObject
So how can I create a query using QueryBuilder that will find all documents that contain a "registrations" array witht he value 101 contained within it?