I've just started to learn mongodb and I'm stuck on a problem. I have the following collection schema:
{
"address":string,
"users" : [{"id":integer, "timestamp":integer}] //users is an array of documents
}
I want to write a query that will fetch me all the user IDs for a particular address given that they are within a certain time frame. I.e. conditions:
1) address : given_address
AND
2) given_timestamp <= timestamp <= given_timestamp + X
Follow up, How do I query ONLY the user IDs instead of all documents, I tried setting
$project:{address:0,users.id:1 , users.timestamp:0 }
but that threw me an error.