I have a MongoDB collection, with one document such as -
{
"_id" : ObjectId("5a187babdbf0a03cdca0d0bc"),
"aggregationDate" : "2017-10-31",
"ipaddress" : "10.65.66.184",
"first" : {
"count" : 3
},
"second" : {
"count" : 2
},
"third" : {
"count" : 3
},
}
There are around 30000 such documents, with around 1000 new ones generated every day. I want to display the "ipaddress" having highest activity, which is defined as highest count of "first", "second" and "third".
I looked up aggregation queries and wrote the following one -
db.collection.aggregate({ $group : { ipaddress: "$ipaddress",
max: { $max : [ "$first.count", "$second.count", "$third.count" }}});
I unfortunately get an error -
"errmsg" : "exception: the group aggregate field 'ipaddress' must be defined as an expression inside an object",
Can someone please help me with this error and also with writing an aggregation query for my requirement? Thanks