0

I have a below data. Would like to search aclpermissions where any of the elements (CRT, READ, DLT, UPD) will match to an array of inputs.

Below query

db.AMSAppACL.find({"aclpermissions.READ" : {'$in': ['58dc0bea0cd182789fc62fab']}}).pretty();

only searches READ element. Is there any way to search all the elements instead of using or queries and aggregate

{
        "_id" : ObjectId("5900d6abb9eb284a78f5a350"),
        "_class" : "com.debopam.amsapp.model.AMSAppACL",
        "attrUniqueCode" : "USER",
        "attributeVersion" : 1,
        "aclpermissions" : {
                "CRT" : [
                        "58dc0bd70cd182789fc62faa"
                ],
                "READ" : [
                        "58dc0bd70cd182789fc62faa",
                        "58dc0bea0cd182789fc62fab"
                ],
                "UPD" : [
                        "58dc0bd70cd182789fc62faa"
                ],
                "DLT" : [
                        "58dc0bd70cd182789fc62faa"
                ]
        },
        "orgHierachyIdentifier" : "14",
        "orgid" : 14,
        "createDate" : ISODate("2017-04-26T17:19:39.026Z"),
        "lastModifiedDate" : ISODate("2017-04-26T17:19:39.026Z"),
        "createdBy" : "appadmin",
        "lastModifiedBy" : "appadmin"
}
2
  • You should create key value pairs if you can do schema changes. Key being name and value being array of ids. Commented Apr 27, 2017 at 19:56
  • It is still key value pair. <stirng key> : [value: array of strings]. Do you want me to do something else i.e. taking it out of aclpermissions? if yes then also how will I achieve my goal Commented Apr 27, 2017 at 20:48

1 Answer 1

0

You should try updating aclpermissions part of schema from dynamic keys to labeled keys.

"aclpermissions":
     [
       {k:"CRT", v: ["58dc0bd70cd182789fc62faa"]},
       {k:"READ", v: [ "58dc0bd70cd182789fc62faa", "58dc0bea0cd182789fc62fab"]}....
     ]

Now you can update the query from post to something like

db.AMSAppACL.find({"aclpermissions.v" : {'$in': ['58dc0bea0cd182789fc62fab']}}).pretty();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.