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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:32:58+00:00 2026-05-28T04:32:58+00:00

I got users, they can create activities and users have friends and each user

  • 0

I got users, they can create activities and users have friends and each user should be able to get all activities from their friends, a single activity can have multiple users.

Users -> _id, name, friendList
Activity -> _id, description, date, involvedUsers

So an example document would be:

"User theo": 1, theo, array(mike, rutger, tijmen)
"User mike": 2, mike, array(theo, rutger, tijmen)

Activity x: 1, 'having fun with friends', {{todaydatetime}}, array(1, 2)
Activity y: 2, 'going out', {{saturdaydatetime}}, array(1, 2)

So now if “theo” logs in, he has to get that Mike is “going to have fun with friends” same if Mike logs in.

And if they select saturday as date, Mike will get that Theo is going out, and Theo would get the activity that Mike is going out.

How can I accomplish this, I know it’s pretty easy in MySql with joins etc, but how can I get all the activities of the users “friendlist” and filtered by a certain date, so for example give me all activities that are happening saturday.

  • 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-28T04:32:58+00:00Added an answer on May 28, 2026 at 4:32 am

    You probably want something like (this is totally untested), and the others are right, if you have too big of arrays (thousands) for your friends lists and your involved, it will probably cause scaling problems:

    collection users:
    {
      _id: objid, 
      name: "theo", 
      friends: [objid, objid, objid] /* these are user object ids */
    }
    
    collection activities:
    {
      _id: objid, 
      desc: "having fun with friends", 
      date: new Date(), 
      involved: [objid, objid, objid] /* these are user object ids */
    }
    

    I would do ensureIndex on date and involved. See here for more information on indexing array values: http://www.mongodb.org/display/DOCS/Multikeys

    db.activities.ensureIndex({date:1});
    db.activities.ensureIndex({involved:1});
    

    So to select the users involved in an activity you would do (from the shell):

    var start_date = new Date(2012, 1, 14);
    var end_date = new Date(2012, 1, 15);
    var friends = db.users.findOne(_id: objid for user).friends;
    var activities = db.activities.find(
       {
         date: {$gte : start_date},
         date: {$lte : end_date},
         involved : {$in : friends}
       });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a site where users submit submissions and they all get displayed on
I've got a form where users can edit members of a group. So they
i got a page users downloading files from there.And when a user click download
I've got around 750+ users that I'm going to create mailboxes for. Should I
We have got a setup where users can either use a web-based form or
I've got a select box where the user selects which elements they want to
I've got 80,000 users on my site and i've recently turned away from the
I've got a rails application where users have to log in. Therefore in order
I've got a number of non-technical users that all share a set of project
My application allows users to write plugins (implementing IPlugin) that they can instantiate 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.