0
[  
   {  
      "_id":"5ba8e3c7433cd30be05538b7",
      "createdAt":"2018-09-24T07:29:16.188Z",
      "subscription":[  
         {  
            "types":"Basic",
            "registeredOn":1542969566953,
            "expires":1545561566953
         }         {  
            "types":"Utility",
            "registeredOn":1542985801375,
            "expires":1545577801375
         },
         {  
            "types":"Demo",
            "registeredOn":1542985801375,
            "expires":1545577801375
         }
      ]
   }
]   

How can I access a user having subscription type 'Demo' from many types in Subscription.

Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71
Saurabh Verma
  • 119
  • 2
  • 2
  • 11
  • Possible duplicate of [Retrieve only the queried element in an object array in MongoDB collection](https://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection) – Ashh Nov 29 '18 at 09:53

1 Answers1

0

try this way :

User.find({"subscription.types": "Demo"},function(err,users){
    if(!err && users){
      return res.json(users);
    }
});
Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71