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

  • SEARCH
  • Home
  • 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 3938764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:13:19+00:00 2026-05-20T00:13:19+00:00

I am beginning with mongodb and have a collection with documents that look like

  • 0

I am beginning with mongodb and have a collection with documents that look like the following

{
    "type": 1,
    "tags": ["tag1", "tag2", "tag3"]
}
{
    "type": 2,
    "tags": ["tag2", "tag3"]
}
{
    "type": 3,
    "tags": ["tag1", "tag3"]
}
{
    "type": 1,
    "tags": ["tag1", "tag4"]
}

With this, I want a set of all the tags for a particular type. For example, for type 1, I want the set of tag1, tag2, tag3, tag4 (any order).

All I could think of is to get the tags and add them to a set in python, but I wanted to know if there is a way to do it with mongodb’s mapreduce or something else. Please advise.

  • 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-05-20T00:13:20+00:00Added an answer on May 20, 2026 at 12:13 am

    If you just want a (distinct) list of the tags then using distinct will be best. Map/Reduce will be slower and can’t use an index for the javascript part.

    http://docs.mongodb.org/manual/reference/method/db.collection.distinct/

    db.coll.distinct("tags", {type:1}) Will return a set of tags for type=1.

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

Sidebar

Related Questions

I'm beginning with MongoDb and nodejs (using mongoose). I have a collection of Stories
I am just beginning to work on android and seems like I have got
I am beginning to use MongoDB with C# and through following a few tutorials
I have the following beginning of a function, and am unsure as to how
I have a PHP app that interacts with MongoDB. Until recently, the app was
I'm just beginning to have a look at Objective-C and Cocoa with a view
I am beginning to research technology for a project, that can have frequent large
I'm beginning to play around with MongoDB and I'm wondering if it's possible to
Since beginning to use VB.NET some years ago I have become slowly familiar with
I am beginning Facebook App development and am following the Recipe Box App Tutorial

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.