1

I am having one document,

{
    "_id" : ObjectId("5bc864fe3cbb0d393687120b"),
    "eStatus" : "y",
    "aQuestions" : [
        {
            "eStatus" : "y",
            "_id" : ObjectId("5bcd7818f0903a1c82aeef85"),
            "sQuestion" : "aabbccdd?",
        },
        {
            "eStatus" : "n",
            "_id" : ObjectId("5bcda6aac272142b96ba77c3"),
            "sQuestion" : "sdfdsf",
        },
        {
            "eStatus" : "y",
            "_id" : ObjectId("5bcda6bfc272142b96ba77c6"),
            "sQuestion" : "vnmhjk",
        },
        {
            "eStatus" : "n",
            "_id" : ObjectId("5bd69f7516972c11234a3613"),
            "sQuestion" : "What is use of Wallet in ParadiseXtrade ?",

        }
    ],
}

My Query: helpFaqsModel.findOne({_id: req.body._id,aQuestions: {$elemMatch: {eStatus: "y"}}})

I am not sure what is the correct way to find the list of questions which has eStatus: "y"

I want to find the first document from the collection and from that collection which has eStatus:"y"

Nikhil Savaliya
  • 1,949
  • 2
  • 17
  • 39
  • Use $filter as noted in the duplicate. – s7vr Oct 31 '18 at 11:50
  • 1
    @Veeram I dont think that is the correct duplicate. OP doesn't want to filter elements, just wants to find the first document match. Would be helpful if if you post your response from the query you are trying and the results you wish to receive – EoinS Oct 31 '18 at 13:04
  • honestly i think that you want to use `helpFaqsModel.findOne({"eStatus":"y"})` – EoinS Oct 31 '18 at 13:04

0 Answers0