Is there any way in MongoDB in which I can specifically query on last object's key value in an array in a single db query.
For eg: This is my doc in a collection.
{
"com" : [
{ "ts" : 1510830164203, "com" : "com1" },
{ "ts" : 1511242569673, "com" : "connected" },
{ "ts" : 1511244832741, "com" : "vb" }
],
"status" : [
{ "ts" : 1510857000000, "stat" : 3 }
]
}
So as you can see there are multiple objects in com. How can I query on last object's ts(timestamp) or I want to check is last com inserted in between today's date or not.
I have already gone through this link. But didn't find the appropriate solution.
Any help can be appreciated.