Q:

Query work in mongo cmd but not in calling method

I am working in mongodb.
I write a query 

db.ekgs.find({_id: ObjectId("54cd1dd3adc274b20a7f650d"),"interpretationList.interpretations" :  { $all:[[ObjectId("54c09fb3581c4c8c218d1a39"),ObjectId("54c09fb3581c4c8c218d1a3a")]]}})

it work in mongo cmd.
but when i write this in a  method that take input from user then it doesn't work.
req.body contain:

    {
    "ekgId":"54cdaed7adc274b20a7f650e",
    "diagnosis":
    [
    "54c09fb3581c4c8c218d1a39",
    "54c09fb3581c4c8c218d1a3a"
    ]
    };

and in my method i write 

modalSchema.find({"_id": req.body.ekgId,'interpretationList.interpretations' :{ $all :req.body.diagnosis , $size: arrLength }});

it always return null.
schema collection:

    {
        "_id" : ObjectId("54cdaed7adc274b20a7f650e"),
        "title" : "Demo Ekg",
        "description" : "Demo Description",
        "diagnosis" : "Demo Diagnosis",
        "ekgImageExtension" : "jpg",
        "urgency" : "Demo Urgency",
        "therapy" : "Demo Therapy",
        "differentialDiagnosis" : "Demo Ddx",
        "history" : "Demo History",
        "references" : "Demo References",
        "fileName" : "",
        "imageURL" : "images/Ekgs/54c09d68581c4c8c218d1a38/54c09d68581c4c8c218d1a38.jpg",
        "interpretationList" : {
            "interpretations" : [ 
                ObjectId("54c09fb3581c4c8c218d1a39"), 
                ObjectId("54c09fb3581c4c8c218d1a3a")
            ]
        },
        "tags" : [ 
            {
                "_id" : ObjectId("54c255da581c4c8c218d2397"),
                "tagName" : "Tag 1"
            }
        ],
        "segment" : [ 
            {
                "explanation" : "Demo Explanation 1",
                "fileName" : "",
                "imageURL" : "",
                "level" : {
                    "_id" : ObjectId("54c25616581c4c8c218d2398"),
                    "levelName" : "Level 1"
                }
            }, 
            {
                "explanation" : "Demo Explanation 2",
                "fileName" : "",
                "imageURL" : "",
                "level" : {
                    "_id" : ObjectId("54c25616581c4c8c218d2398"),
                    "levelName" : "Level 1"
                }
            }
        ]
    }

A:

You should convert all the elements of the diagnosis array in the request object to ObjectIds instead of strings. Then execute your query on Mongo 
here is a code snippet to convert an array of strings into an array of ObjectIds
var result = interpretationList.interpretations.map(function (x) { 
    return ObjectId(x); 
});

then in your query you use the result object instead of req.body.diagnosis
modalSchema.find({"_id": ObjectId(req.body.ekgId),'interpretationList.interpretations' :{ $all :result , $size: arrLength }});

