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 9176423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:06:26+00:00 2026-06-17T17:06:26+00:00

below is my collection in mongodb – { _id : ObjectId(50f69176904e1d66affec20d), connections : [

  • 0

below is my collection in mongodb –

{
    "_id" : ObjectId("50f69176904e1d66affec20d"),
    "connections" : [
    {
        "id" : "50f651a3b58bba7fbec2f222"
    },
    {
        "group" : "Roomies",
        "users" : [
        {
            "id" : "50f651a3b58bba7fbec2f222"
        },
        {
            "id" : "50f651b8b58bba7fbec2f223"
        }
        ]
    },
    {
        "group" : "College",
        "users" : [
        {
            "id" : "50f651b8b58bba7fbec2f223"
        },
        {
            "id" : "50f651a3b58bba7fbec2f222"
        }
        ]
    },
    {
        "group" : "Work",
        "users" : [
        {
            "id" : "50f651a3b58bba7fbec2f222"
        }
        ]
    },
],
"email" : "arunko350@gmail.com",
"name" : "Arun"
}

Here i want to get all the group names in which id = 50f651a3b58bba7fbec2f222 exists. Please help me. I am browsing for 2 days for the solution.

  • 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-17T17:06:27+00:00Added an answer on June 17, 2026 at 5:06 pm

    You can do this with MongoDB 2.2’s aggregation framework. In the shell:

    db.test.aggregate([
          // Duplicate the docs, one per connections array element.
          {$unwind: '$connections'},
          // Only include the docs with the specified user id
          {$match: {'connections.users.id': '50f651a3b58bba7fbec2f222'}},
          // Bring group out to the only top level field and exclude _id
          {$project: {_id: 0, group: '$connections.group'}}
    ])
    

    outputs:

    {
      "result": [
        {
          "group": "Roomies"
        },
        {
          "group": "College"
        },
        {
          "group": "Work"
        }
      ],
      "ok": 1
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MongoDB collection Marks as shown below _id Student_id Subject Mark 1
I have the following mongodb structure { _id: ObjectId(507c80a143188f9610000003), date: ISODate(2012-10-15T21: 31: 13.0Z), uid:
I am using mongoDB database. in which I have collection in below format. {
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I thought of solution below because the collection is very very small. But what
I have 3 collection datatable that shows in this below Month: January ID NAME
i am adding collection of radio buttons to my page using jQuery below $(document).ready(function()
I have a large (more than 100K objects) collection of Java objects like below.
Please take a look at the code snippet below. I want the 2nd MongoDB
I'm using MongoDB with PHP to store songs which users add via a basic

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.