mongodb - jongo find subdocuments with array of values -
my info looks this:
"_id" : objectid("53a173630364206735975b35"), "username" : "testuserid", "resources" : [ { "id" : "firsttestresourceid", "tags" : [ "testresourcetag1", "testresourcetag2" ], } { "id" : "secondtestresourceid", "tags" : [ "testresourcetag1", "testresourcetag2" ], } ] what retrieve resource documents user of tags match fellow member of array of strings.
when do:
db.collection.find({username: 'testuserid', 'resources.tags': { $in: ['testresourcetag1']}}) it seems work fine (as in brings right document right resource subdocument, when seek in java class brings nada.
iterable<resource> resources = usercollection.find("{username: #, 'resources.tags': { $in: #}}", userid, tags).as(resource.class); where userid = string , tags = string[]
i guess i'm doing dim in query, can't seem find reply anywhere.
i'd grateful guidance problem.
use list<string> instead of array of string tags variable, instead of
string[] tags = new string[]{"testresourcetag1"}; try using
list<string> tags = arrays.aslist("testresourcetag1"); hope helps.
mongodb jongo
No comments:
Post a Comment