[SERVER-8834] MongoDB return fields from subdocuments in an array Created: 03/Mar/13 Updated: 08/Mar/13 Resolved: 05/Mar/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Minor - P4 |
| Reporter: | Kurt Agius | Assignee: | Ian Whalen (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
I have a document such as: {_id: ObjectId("512fe1e5b9912a714eef4e54"), , {type:'test', name:'my second object'}]} Basically i need to list all the names in my items array something similar to: db.log.findOne({_id:ObjectId("512fe1e5b9912a714eef4e54")},{'items.$':{name:1}}); Is there another way to do it ? Or is it even planned/discussed somewhere ? |
| Comments |
| Comment by Kurt Agius [ 05/Mar/13 ] | |||||||||||||||
|
Works perfect, thanks | |||||||||||||||
| Comment by Ian Whalen (Inactive) [ 04/Mar/13 ] | |||||||||||||||
|
Kurt, without more specifics about your desired output, it sounds like this should work for you if you're on 2.2.x or later and can use the aggregation framework:
which will output this:
or were you looking for something different? |