0

My document:

{
  currentRole: { title: "Engineer"}
}

Desired output

{
  role: "Engineer"
}

Tried this:

let query = mongoose.model('cvs').aggregate(
    [
        {
            $project: {
               "currentRole.title":1,
               "_id": 0
            }
        }
    ]
);

But this gives:

  {
    "currentRole": {
      "title": "Engineer"
    }
  },

How can I created a new field with the title value?

Joe
  • 4,274
  • 32
  • 95
  • 175

1 Answers1

1

replace your project stage to use the value of the field like this :

   {
        $project: {
           "role": "$currentRole.title",
           "_id": 0
        }
    }
felix
  • 9,007
  • 7
  • 41
  • 62