My data looks like this:
"_id" : ObjectId("53a173630364206735975b35"),
"username" : "TestUserID",
"resources" : [
{
"id" : "FirstTestResourceId",
"tags" : [
"TestResourceTag1",
"TestResourceTag2"
],
}
{
"id" : "SecondTestResourceId",
"tags" : [
"TestResourceTag1",
"TestResourceTag2"
],
}
]
What I would like to do is retrieve all the resource documents for a user where any of the tags match any member of an array of Strings.
When I do:
db.collection.find({username: 'TestUserID', 'resources.tags': { $in: ['TestResourceTag1']}})
it seems to work fine (as in it brings back the correct document with the correct resource subdocument, but when I try it in my java class it brings back nada.
Iterable<Resource> resources = userCollection.find("{username: #, 'resources.tags': { $in: #}}", userID, tags).as(Resource.class);
Where userID = String and tags = String[]
I guess I'm doing something dim in the query, but I can't seem to find the answer anywhere.
I'd be most grateful for any guidance with this problem.