Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:50:43+00:00 2026-06-12T13:50:43+00:00

I am trying to write a blog engine for myself with node.js/express/mongodb (also a

  • 0

I am trying to write a blog engine for myself with node.js/express/mongodb (also a start to learn node.js). To go a little further than the tutorials on the Internet, I want to add tags support to the blog engine.

I want to do the following things with tags:

  1. Viewers could see all the tags as a tag cloud on a “tag cloud page”
  2. Viewers could see the tags that an article has on article list page and single article page
  3. Viewers are able to click on a single tag to show the article list
  4. What’s more, viewers are able to search articles with particluar tags in the SO way: [tag1][tag2] –> /tags/tag1+tag2 –> list of articles that has both tag1 and tag2

In relational database, a post_tag table will be used for this. But how to desgin this in MongoDB?

I have checked MongoDB design – tags
But as efdee comments, the design

db.movies.insert({
  name: "The Godfather",
  director: "Francis Ford Coppola",
  tags: [ "mafia", "wedding", "violence" ]
})

has a problem:

This doesn’t seem to actually answer his question. How would you go about getting a distinct list of tags used in the entire movie collection?

That’s also my concern: in my design, I need to show a list of all the tags; I also need to know how many articles each tag has. So is there a better way than the design shown above?

My concern with the design above is: if I want to show a list of the tags, the query will go over all the article items in the database. Is there a more efficient way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:50:44+00:00Added an answer on June 12, 2026 at 1:50 pm

    You’d need to create a multi key index on tags to start with.

    Then you will be able to find document matching tag using this syntax

    db.movies.find({ "tags": { $all : [ /^this/, /^that/ ] }})
    

    Because you’re using the ^ (start of string) of the reg ex mongo will still use the index.

    To get keyword densities, using the aggregation framework, you could simple get a count.

    db.movies.aggregate({ $project: { _id:0, tags: 1}}, 
        { $unwind: "$tags" },
        { $group : { _id : "$tags", occur : { $sum : 1 }}})
    

    Sorry formatting difficult from iPad.

    You would end up with collection of docs looking like:

    {
       _id: "mytag",
       occur: 383
    },
    {
       _id: "anothertag",
       occur: 23
    },
    

    Using the aggregate command you get an inline result back, so would be down to the client app (or server) to serialise or cache the result if it’s frequently used.

    Let me know how you get on with that.

    Hth

    Sam

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to install a file-based blog engine in XAMPP, but all of these
Simple situation. I'm trying to write my own blog with a minor twist. Part
So i'm trying to get the category filter on my Expression Engine blog to
i am trying to write a blog application with CodeIgniter just for practice and
Need a guide line .... I am trying to write a personal blog. What
I'm trying to write and RSS reader for a wordpress blog. My news element
Now I am trying to use Octopress on Windows system.When I write a blog
Following this tutorial http://johnsquibb.com/tutorials/mvc-framework-in-1-hour-part-one Im trying to write my first MVC Blog. I understood
I'm trying to write a blog post which includes a code segment inside a
I'm trying to write a Wordpress plug-in that automatically posts a blog post at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.