Minimongo from client-side memory


#1

BACKGROUND

I have have an app where I have 6 collections: tournaments, teams, players, schedule, rosters and memo

_id from tournaments collection’s can be found in all other five collections as tournament_id

I have Iron Router installed and when hitting the URL http://myip/_id, Iron Router sets _id for the session which acts as condition to all Mongo queries that I have created for my application.

This works ok, but I have created about 30 find() queries to process my data and make joinings, even I have only 5 collections to be used.

What I am looking for

I was thinking that

  1. when hitting the URL http://myip/_id
  2. I could used Iron Router to fetch these 5 five collection to browser’s memory, filtered by URL _id
  3. and then use MiniMongo and JavaScript to process these collections from browser’s memory

This could be possible and fast, as when filter, each collection will have only 10-200 documents and each document only 5-10 fields inside.

But how I do it?


#2

Hi,

you could use waiton and subscribe to all 6 collections:

waitOn: function() {
        return [Meteor.subscribe('firstCollection', this.params._id),
        Meteor.subscribe('secondCollection', this.params._id)];
}

#3

So when using subcribe browser establish “live local storage” instead of going for database?


#4

Something else to consider - you could look into handling all data fetching, joining, massaging, etc. via a Method, then call that Method and store the results in a local (mini mongo only) collection. There are pros/cons to this approach - check out the Guide’s Loading data with Methods section.


#6

Got it working. Seems to be super fast :heart_eyes:


#7

@tarkancorak can I have an additional question. I have Iron Router setting the conditional collections by URL, but what about the _id’s “sub-folders”.

  1. My site’s main address is http://myip/ where I have links for the tournaments
  2. Each tournament has it’s own public URL http://myip/_id where Iron Router is limiting the collections as you suggested
  3. But each tournament has also admin panel
    http://myip/_id/admin
    http://myip/_id/admin/tournament
    http://myip/_id/admin/teams
    http://myip/_id/admin/players
    http://myip/_id/admin/schedule

how can I set conditional collections for these all at the once?


#8

Not sure if I understood you correctly, but each URL would have it’s own route configuration where you define what ever you need.


#9

I would like to have one configuration for Admin 5 URL/pages, so all collections would not be reloaded when moving around my admin panel. I think I would like to subcribe collection for user?


#10

I would suggest that Meteor is clever enough not to reprocess the subscription for all routes. But if you want to avoid redundant code, define one controller, do the subscriptions there and assign the controller to the routes.