4

Mongodb, a collection named 'blog' has a 'tags' field, just like this

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

now I need a hot tag list, which like this

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

how can I do it?

2
  • Please do basic search by using a simple google search and you will find this: cookbook.mongodb.org/patterns/count_tags Commented Mar 20, 2011 at 7:49
  • You can use aggregation pipeline like group({"_id":"tags","count":{"$sum":1}}) Commented Dec 25, 2019 at 5:47

1 Answer 1

2

In Mongodb 2.2 you will be able to use the aggregation framework and the $unwind and $group commands. Check out their demo here and the demo source code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.