motorcb
motorcb

Reputation: 1051

MongoDB aggregate tweets - not case sensitive

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

Answers (1)

Parshuram Kalvikatte
Parshuram Kalvikatte

Reputation: 1646

We think too much,but the solution sometimes is really easy and small. "_id": { "$toLower": "$entities.hashtags.text" }

Upvotes: 1

Related Questions