0
{
   "_id": NumberInt(13),
   "name": "vishal",

   "friends": [
     {
       "name1": "vini",
       "count": NumberInt(213) 
   },
   {
       "name1": "sumesh",
       "count": NumberInt(47) 
   }],
   "blog": NumberInt(5) 
}

i need to display the name,name1 of all doc & blog in php , using foreach() i got the parent document "name" but dint get name1& blog ?

Gopal Joshi
  • 2,350
  • 22
  • 49
vishalvvr
  • 82
  • 6
  • you can try unwind in aggregation pipeline – Rohit Jain Oct 04 '15 at 04:29
  • 3
    Possible duplicate of [Retrieve only the queried element in an object array in MongoDB collection](http://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection) – styvane Oct 04 '15 at 05:44
  • Can you include the PHP code you are using to find and iterate? From the current description it's not clear why the embedded document fields aren't being included, but the problem is likely in how you are iterating the results. – Stennie Oct 11 '15 at 12:54

1 Answers1

-1

you can try unwind in aggregation pipeline

db.collection.aggregate([{$unwind:"$friends"}])

Hope it will help

Rohit Jain
  • 2,052
  • 17
  • 19