12

How do I project the author's first name using a MongoDB query

{
 name: "Wings Of Fire",
 author:
 {
  first: "Abdul",
  last: "Kalam"
 }
}

1 Answers1

23

You can use dot notation in the field selector to project subdocument fields. In the shell:

db.test.find({}, {'author.first': 1})
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
  • 2
    $project can also be used. `db.test.aggregate([{$project:{"_id":1,"author.first":1}}])` – ann Feb 26 '13 at 08:46