Skip to content

Instantly share code, notes, and snippets.

@alfredfrancis
Created March 5, 2020 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredfrancis/1d6ff8fc333e771520d5664d31dfffde to your computer and use it in GitHub Desktop.
Save alfredfrancis/1d6ff8fc333e771520d5664d31dfffde to your computer and use it in GitHub Desktop.
Wordcloud using mongodb data
db.getCollection('cogniwidebot').aggregate([
{
"$project": {
"words": { "$split": ["$query", " "] }
}
},
{
"$unwind": {
"path": "$words"
}
},
{
"$group": {
"_id": "$words",
"count": { "$sum": 1 }
}
},
{ "$sort": { "count": -1 } },
{ "$limit": 5 }
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment