I have array in a document, and I try to receive the last element of this array.
My code is:
Post.find({_id:postId},{'comments':{'$slice':-1}});
this gives me all the object but the comments array contains only the last element.
on the other hand,
Post.find({_id:postId},{'comments':1});
give me only the comments.
I dont find how to combine the two commands together. How it can be done?
{
"users":[],
"comments":["string1","string2","string3"],
"lastValue":"Wow"
"name":"jow"
"_id": {
"$oid": "5747d6bdecfae9d0560077cc"
},
}
Thanks