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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:24:12+00:00 2026-05-24T04:24:12+00:00

I am building a social network in mongo db. Following is the structure of

  • 0

I am building a social network in mongo db.
Following is the structure of document in the groups collection. It represents each social group present in the system. Users are a part of this group which is represented by the ‘members’ property which is an array if json objects.

{
  "group_name":"my group",
  "members": [
    {
      "user_id": ObjectId("4e29341986ba75dc14000000"),
      "joined": ISODate("2011-07-26T11:46:49.0Z")
    },
    {
      "user_id": ObjectId("4e2ea94286ba75f81500000e"),
      "joined": ISODate("2011-07-26T11:47:55.0Z")
    },
    {
      "user_id": ObjectId("4e2eaa0786ba75e815000003"),
      "joined": ISODate("2011-07-26T11:55:22.0Z")
    },
    {
      "user_id": ObjectId("4e2eab7f86ba75ec1500000a"),
      "joined": ISODate("2011-07-26T11:57:44.0Z")
    },
    {
      "user_id": ObjectId("4e2eac3586ba75dc15000000"),
      "joined": ISODate("2011-07-26T12:00:57.0Z")
    },
    {
      "user_id": ObjectId("4e2eacae86ba75dc15000004"),
      "joined": ISODate("2011-07-26T12:02:43.0Z")
    },
    {
      "user_id": ObjectId("4e2eadbb86ba75ec1500000c"),
      "joined": ISODate("2011-07-26T12:07:01.0Z")
    }
  ]

The problem I am facing is how do I check if a user belongs to a certain group.
This is what I came up with but it doesn’t seem to work.
Please help.

    $criteria = array(
        '_id' => new MongoId($group_id),
        'members' => array('user_id' => new MongoId($user_id))
    );


   return $collection->find($criteria);
  • 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-24T04:24:13+00:00Added an answer on May 24, 2026 at 4:24 am

    try with the following code:

    $criteria = array(
            '_id' => new MongoId($group_id),
            'members.user_id' => new MongoId($user_id))
        );
    
    
    return $collection->find($criteria);
    

    see http://www.mongodb.org/display/DOCS/Dot+Notation+%28Reaching+into+Objects%29

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

Sidebar

Related Questions

I'm building a social network. For each user, I'm going to expect a lot
I´m building a social network with Grails and got stucked on giving users inner
I am building a server back-end for a mobile social network using Windows Azure.
I am working on a user based social network. I am building the site
Building an inventory system. I have lots of products and each product has three
i am building a social network platform, as a platform to learn web development.
I'm trying to create a social-network like feature in an app I'm building, and
I'm building a service, kind of a social network, that is expected to attract
I'm following along with RailsSpace: Building a Social Networking Website with Ruby on Rails
Building a social network, I'm trying to fetch live notifications. Currently, the site sends

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.