Lets suppose we have the following collection:
{
"_id" : 10,
"youtube_id" : "xxx",
"title" : "yyy",
"counters" : [
{
"timestamp" : 202003181300,
"views" : 7433,
"likes" : 2477,
"dislikes" : 34,
"comments" : 105
},
{
"timestamp" : 202003200815,
"views" : 12494,
"likes" : 4877,
"dislikes" : 248,
"comments" : 322
}
]
}
{
"_id" : 11,
"youtube_id" : "xxz",
"title" : "yyz",
"counters" : [
{
"timestamp" : 202003181300,
"views" : 12,
"likes" : 2,
"dislikes" : 0,
"comments" : 0
},
{
"timestamp" : 202003200815,
"views" : 198,
"likes" : 50,
"dislikes" : 4,
"comments" : 36
}
]
}
And I want to query for the number of comments given a certain timestamp and title, my guess would be to do as follows:
db.youtube.find({"title":"yyy","counters.timestamp":{$eq:202003181300}},{"_id":0,"title":1,"counters.timestamp":1,"counters.comments":1}).pretty()
And the result I am getting is the following:
{
"title" : "yyy",
"counters" : [
{
"timestamp" : 202003181300,
"comments" : 105
},
{
"timestamp" : 202003200815,
"comments" : 322
}
]
}
The problem is that I would only like to see the part that has the same timestamp I have done the query for, like this:
{
"title" : "yyy",
"counters" : [
{
"timestamp" : 202003181300,
"comments" : 105
}
]
}
Is there a way to do it, and in case I am missinterpreting what the query does could anyone give me a piece of advice? Thanks in advance
Ps. It is my first post, and I am learning the mongo basics so forgive me if I have said anything wrong.