Gurus - I'm stuck in a situation that I can't figure out how I can query from the following collection "users", it has 2 embedded documents "signup" and "activity":
{
"appid": 2,
"userid": 404915,
"signup": {
"dt": "2010-12-28",
"platform": 2
},
"activity": {
{
"dt": "2010-12-28",
"platform": 3,
"login_count": 8,
"game_completed": 13
},
{
"dt": "2010-12-30",
"platform": 3,
"login_count": 8,
"game_completed": 13
} ,
{
"dt": "2010-12-31",
"platform": 3,
"login_count": 8,
"game_completed": 13
}
}
},{"appid":2,"userid":404915...}
I need to query:
unique logins of users who signed up between Date and Date+7 and logged in within Date
Then:
Unique logins of users who signed up between Date and Date+7, and logged in between Date+7 and Date+14
PLEASE PLEASE Guide me how I can achieve this any example/sample? based on this will be really helpful :-)
Thanks a lot!
find() is a function that retrieves documents from a MongoDB database. In MongoDB, the find method is used to retrieve a specific document from the MongoDB collection.
Specify a Query Condition on a Field Embedded in an Array of Documents. If you do not know the index position of the document nested in the array, concatenate the name of the array field, with a dot ( . ) and the name of the field in the nested document.
The MongoDB find query is an in-built function which is used to retrieve the documents in the collection.
Here is how you get the result for your first query:
var start = new Date(2010, 11, 25);
var end = new Date(2010, 12, 1);
db.users.distinct("userid", {"signup.dt" : {$gte: start, $lte: end},
"activity" : {"$elemMatch" : { dt: {$gte: start, $lte: end}}}});
The second is like it with adding 7 days to the start and end date to the dates after activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With