Hi,
Intro:
I needed to make a local collection hold a temporary list of results coming from a third party API.
The reason I choose for a local minimongo collection is to easily implement a Show More option.
I create a local collection like this (CoffeeScript);
@EpisodeList = new Meteor.Collection null
Question: In a Meteor method I receive the full data of the third party api. There I run an forEach loop inserting each record in my local collection.
results.episodes.forEach ( item, idx ) ->
EpisodeList.insert
title: item.title[ 0 ]
description: item.description[ 0 ]
Now I thought I read somewhere in the docs that a collection can be accessed on client as server.
I am not sure if this is also the case for a non persistent collection like mine.
when I run the method and then in my client do Episode.list.find().fetch() I always see an empty array as result.
When I do a console.log on the server just before the return of my method, I see the EpisodeList is full of documents.
To test my assumption that the collection only lives on the server, I added another method that retrieves the documents from the server.
getEpisodes: ( filter)->
return EpisodeList.find().fetch()
Executing this call from the client results in many documents.
So I have a working solution, using another call. But I thought Meteor would automatically push this collection to the client so that I can access it.
Setting up a subscriber can’t be done with a non persistent collection (right)?
Hope that someone can shed some light.
Cheers
UPDATE: I have another issue: the collection is public right now. Can you make it private for each client that access the application? I haven’t implemented users yet but if so, I should do that now
UPDATE 2: This probably answer both my questions: I have moved the EpisodeList.insert to the client, which inserts the data in the client minimongo (duh!!).
I just wanted to prepare all data in the server method call, seemed to be the right place for grabbing the data and put it in a non persistent collection. But of course, it can never be private per client that way, right?