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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:33:19+00:00 2026-06-09T12:33:19+00:00

Goal I have a top-level Collection named Players and a Session variable called ‘n’.

  • 0

Goal

I have a top-level Collection named Players and a Session variable called ‘n’. In addition to my top-level Collection, I’d like to have a Collection of the top-‘n’ Players based on player.points, which updates in reaction to Session.set('n', n) (and, of course, any changing of the underlying Players data).

Rationale

The reason I would like a TopNPlayers is because within each player template (call it Template.player_item) I want to provide a couple of variables:

  • Template.player_item.isInTopN, which sets a CSS class to highlight a player if it’s in the top-‘n’ in points
  • Template.player_item.PointsVsBaseline, which gives the difference between that player’s points and the ‘n’th player in TopNPlayers.

Since I don’t want to manually manage a global variable containing Players filtered by the value of Session.get('n'), and I certainly don’t want to calculate the top-‘n’ every time I render another player_item, I’d like to set up an additional subscription to the Players Collection.

  • 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-09T12:33:20+00:00Added an answer on June 9, 2026 at 12:33 pm

    I’m not sure you need a separate collection, wouldn’t a cursor do the trick?

    Something like:

    var topNPlayers = function() { 
      return Players.find({}, {limit: Session.get('n')}); 
    }
    
    Template.player_item.isInTopN = function() {
    
      // there are a bunch of ways you could do this step...
      _.include(topNPlayers().fetch(), this);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal is to have the member variable _AddValue point to the CreateFirstValue function
I have the following goal: I Have a list of top menu links on
I'm trying to have text in the top level of a RibbonApplicationMenu (trying to
I have a query to fetch the top 50 entries based on a total_score
In my application I have a Form that for one of the top level
Final goal: Have a few java objects sharing the same base class persisted into
goal: I have the string 1234432144 I want to only replace the first 2
Let me first describe my goal: I have created an object with 3 properties:
My goal is to have an Android phone (Samsung Galaxy Nexus) communicate with a
My goal is to have the url routing as following: http://www.abc.com/this-is-peter-page http://www.abc.com/this-is-john-page What is

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.