in Education by
Input: {_id:ObjectID(123),ip:'123.123.123.123'} {_id:ObjectID(123),ip:'123.123.123.123'} {_id:ObjectID(124),ip:'123.123.123.124'} {_id:ObjectID(125),ip:'123.123.123.125'} Output: {2019-03-20: 1} {2019-03-21: 1} {2019-03-22: 1} I'm messing around with this all day to extract the timestamp from the mongo ID and use it to do a daily distinct count on the IP but I'm not getting it... I always end up with a per IP count, as in IP on day X was found 4 times... not unique IPs on day X. Thanks! JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use $toDate and $dateToString to get date from ObjectId and then use $addToSet to get unique IP addresses per day. In the last step you need $size to get length of ip array: db.collection.aggregate([ { $group: { _id: { $dateToString: { date: { $toDate: "$_id" }, format: '%Y-%m-%d' } }, ip: { $addToSet: "$ip" } } }, { $project: { _id: 0, date: "$_id", ipCount: { $size: "$ip" } } } ])

Related questions

0 votes
    Input: {_id:ObjectID(123),ip:'123.123.123.123'} {_id:ObjectID(123),ip:'123.123.123.123'} ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    Input: {_id:ObjectID(123),ip:'123.123.123.123'} {_id:ObjectID(123),ip:'123.123.123.123'} ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I tried mongo replica sets for the first time. I am using ubuntu on ec2 and I booted up three instances ... replicate across machines? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I want to query something with SQL's like query: SELECT * FROM users WHERE name LIKE '%m%' How to do I ... like in the documentation. Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I have two collection vmdetails and rsc_installtion_status , i want to select the documents from rsc_installtion_status ... Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I have a requirement to return the same length of the array provided to mongo. usernames = ['user1' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Following query is perfectly working in mongo shell. db.collection.find({ "_id" : UUID("87aa9ed6-8485-4517 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have a dataframe: > myvec name order_no 1 Nehal 12 2 sejal 14 3 sejal 16 4 shyam 11 5 Nehal 12 6 Sejal 16 ... Sejal 3 Shyam 1 Ram 1 Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Let's say there is a table structured like this: ID | article_id | article_count | created_at ---| ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    Let's say there is a table structured like this: ID | article_id | article_count | created_at ---| ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I'm getting unexpected results for getting the collections between two columns. I have this simple collection: ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I'm getting unexpected results for getting the collections between two columns. I have this simple collection: ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Which of the following input control represents a date (year, month, day) encoded according to ISO 8601 in Web Form 2.0?...
asked Apr 10, 2021 in Education by JackTerrance
0 votes
    To retrieve the day of the month from the Date object, which is the code to select? var date_obj = new Date(2016,1 ... = date_obj.getMonth(); 4. var month_day = date_obj.getDate();...
asked Feb 24, 2021 in Technology by JackTerrance
...