Collections vs SIngle Item?

So I have a simple application. That application is basically just a pre-defined set of variables. I need all of the clients to have the same data. I was looking at collections, but that seems like overkill for my needs. Really it’s just a single object/json that needs to be shared. What is the correct way to do this?

E.g. I need…

myData = {
field1: “Some Data”,
field2: “Some Data”,
etc.
}

Shared among all of the clients. I don’t really need any more data (not a list or array or anything). Just a pre-defined hash.

Thanks!

If the data won’t change, you can simply store it in an ordinary variable.

1 Like

Use Meteor.settings?

It isn’t static data… It is basically an object with a bunch of string values and a few arrays… But there is only one of them. I could just put the single item into a collection…

My goal is to have a web page. That web page has about 20 fields on it. I want to be able to load up that page in a bunch of browsers and have it be editable. All changes should go to all clients. I don’t need to add or remove any data. Just the single page…

Thoughts? Suggestions?

If you want the client pages to automatically live update, you’re going to need a collection, and reactivity to push it from the server.

If updates on page-load or page-refresh are enough, put everything in a data.json file on the server. Client-side, you GET the json file, and parse it into your page. Meteor way: have the client do a method call to the server, which loads the file and sends it to the client.

If it updates only rarely, and it’s ok to restart the meteor server, put it in the public part of Meteor.settings ( I think Meteor has to restart to pick up the changes)

Use 1 collection called “Posts”.

Each post has a bunch of fields, so you end up with:

Post

  • Field 1
  • Field 2
  • Field 3

When your clients connect, subscribe them to your Post collection, which will transfer in this one post with many fields.

I hope this helps, cheers.

Thanks all. I’m just going to use a collection with a single field.