Harry
Harry

Reputation: 121

How to use elemmatch in in mongojack in Java

Given a mongoDB collection containing the following:

{ 
"_id" : ObjectId("561c04bde4b05625eaaaf691"), 
"groupName" : "Group1", 
"Rights" : [
    "RIGHTS_1", 
    "RIGHTS_2"
], 
"users" : [
    "User 1"
]}


,{ 
    "_id" : ObjectId("561c04bde4b05625eaaaf692"), 
    "groupName" : "Group2", 
    "Rights" : [
        "RIGHTS_3", 
        "RIGHTS_4"
    ], 
    "users" : [
        "User 2"
]}

I have a query like this

db.collection.find({Rights:{$elemMatch:{$eq:"RIGHTS_1"}}})

, looking for the groups that has rights matching RIGHTS_1.

However, I'm not sure how to write the equivalent query using MongoJack, since in MongoJack, I have something like

DBQuery.elemMatch(collection.RIGHTS_FIELD, DBQUERY_GOES_HERE))

but DBQuery must have a field and a value, and doesn't seem to allow equality check within an array. I checked other posts and the documentation but I couldn't seem to find a solution. Is this kind of query supported in MongoJack? I appreciate the help!

Upvotes: 1

Views: 522

Answers (1)

Harry
Harry

Reputation: 121

I was being really dumb.

db.collection.find({Rights:{$eq:"RIGHTS_1"}}})

is a sufficient query and is easy to implement

Upvotes: 1

Related Questions