Reputation: 1051
i have tweets in MongoDB database. Structure:
{
"_id" : ObjectId("111111111111111111"),
//...
"entities" : {
"hashtags" : [
{
"text" : "HASTAG",
"indices" : [
25,
33
]
}
],
},
}
{
"_id" : ObjectId("222222222222222222222"),
//...
"entities" : {
"hashtags" : [
{
"text" : "hashtag",
"indices" : [
25,
33
]
}
],
},
}
How to group by hastgas count with not case sensitive hashtags?
db.getCollection('tweets').aggregate(
{ '$unwind': '$entities.hashtags'},
{ '$group': { '_id': '$entities.hashtags.text', 'tagCount' : {'$sum' : 1} } } ,
{ '$sort': {'tagCount': -1 } }
)
This example is OK, bud case sensitive. How to make it not case sensitive?
Thanks
Upvotes: 1
Views: 268
Reputation: 1646
We think too much,but the solution sometimes is really easy and small.
"_id": { "$toLower": "$entities.hashtags.text" }
Upvotes: 1