Mongodb: how to make group and array field aggregation

Mongodb, a collection called "blog" has a "tags" field, just like that

blog1.tags=['javascript', 'node.js', 'express'] blog2.tags=['javascript', 'jquery'] blog3.tags=['javascript', 'node.js'] 

now i need a list of hot tags that like this

 [['javascript', 3], ['node.js', 2], ['express', 1], ['jquery', 1]] 

How can i do this?

+4
source share
1 answer

In Mongodb 2.2, you can use the aggregation structure and the $ unwind and $ group commands. View the demo and demo source code .

+2
source

Source: https://habr.com/ru/post/1344427/


All Articles