I am trying to get specific object value from items array. I am updating array by pushing new items into items array and then I want to get last updated item from an array. I have _id of the item that is last updated and using this query but it's returning complete record with all items.
let repData = Items.findOne({'_id': rid, 'items._id': newRepId },{ "items.$": 1 });
{
"errorCode": false,
"data": {
"_id": "NhNpaN8EHn6uJXfg5",
"cText": "Let me know you views",
"aId": "YxEjFqsE3czZZJvgP",
"cId": "EwDS5iYSEuGThHE38",
"datePosted": "2019-07-11T07:13:59.177Z",
"items": [
{
"reText": "pppppp sssssssss",
"reOwn": "FK7KQ7eMs7QvX5uHh",
"datePosted": "2019-07-11T07:19:17.722Z",
"_id": "b87e532807ce37ff83d37a09"
},
{
"reText": "bbbbbb vvvvvvvv",
"reOwn": "FK7KQ7eMs7QvX5uHh",
"datePosted": "2019-07-11T07:22:36.089Z",
"_id": "28d2bf66a517bfcfaa0fabca"
},
{
"reText": "mmmmmnnnnnn bbbbbbvvvvv",
"reOwn": "FK7KQ7eMs7QvX5uHh",
"datePosted": "2019-07-11T07:23:20.587Z",
"_id": "85f52e3e3a8ae6d18e98dbb2"
},
}
}