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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:22:49+00:00 2026-05-28T18:22:49+00:00

i’m trying to figure out a way to record a user plays without slowing

  • 0

i’m trying to figure out a way to record a user plays without slowing down my application just like iTunes.

my application is basically a music website its heavily integrated with facebook, facebook users can log in and approve my application and start listening to songs and make their own playlists etc..

the application is built using php and mongodb.

i tried adding this feature 2 times already but each method has its own flaws, i just want to see what you “pros” think because i have only 1 year experience in building applications.

method 1

make a collecton named plays and each document will look like this.

{
"user" => "user mongoid",
"track" => "track mongoid"
}

the problem with method 1

the problem with this one is that it will be very slow, because when i display the artist page
i will have to list the 20 most recent tracks, then when getting the tracks i will have to check for each track how much the current user listened to it.

so after getting the tracks i will have to this to get the current user plays:

// getting the tracks.
$cursor = $this->tracks->find();
$tracks = array();

foreach ($cursor as $t) {
  // getting the number of plays.
  $t['plays'] = $this->plays->find(array('user_id' => $user, 'track_id' => $t['_id']))->count();
  $tracks[]   = $t;
}

method 2.

embed plays in the user document.
this method seemed ok and it was pretty fast, when a user plays a track just add or increment the number of tracks for this track.
and then just display them.

the problem with this method. MongoDB allows only 4 mb for document. i cant just push everything in the user document.

i looked all over the net for someone who ran into similar problem with mongo but i didnt find any.

So how can i record per user plays without making the application slower ?

  • 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-28T18:22:51+00:00Added an answer on May 28, 2026 at 6:22 pm

    I’m not familiar with MongoDB, but wouldn’t it make more sense to change your ‘play’ document to something like:

    { "user" => "user mongoid", "track" => "track mongoid", "plays" => "number of plays" }
    

    That way you don’t have to do a count when you display the artist overview. I suspect MongoDB can do very fast lookups/updates, but based on other questions (like MongoDB's performance on aggregation queries) aggregation seems to be fairly slow.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.