0

I am learning Meteor using the Discover Meteor book.

I come from a PHP and MySQL background, and the application I am thinking of doing as a side-project is a real-time Backgammon web application. While Meteor's reactivity is a very, very big plus, I am stumped on how I can handle relational data (e.g. games, users, tournaments, friends, teams, etc).

I have read a lot of answers (ranging from old to very old) on StackOverflow on how one can use MySQL with Meteor. My search has led me to numtel/meteor-mysql. However, when I look at the examples provided in that repository, it is nowhere as clean as Meteor's own implementation of MongoDB.

My options, as I understand them, are the following:

  • Use MongoDB, and rewrite a lot of the features present in RDBMS in Javascript
  • Use an RDBMS that is not as well-supported in Meteor as MongoDB

IMO, option two is much less work, and I think might lead to less problems in the future. Take the problem in the epilogue of Why You Should Never Use MongoDB, for example.

We could also model this data as a set of nested hashes. The set of information about a particular TV show is one big nested key/value data structure. Inside a TV show, there’s an array of seasons, each of which is also a hash. Within each season, an array of episodes, each of which is a hash, and so on. This is how MongoDB models the data. Each TV show is a document that contains all the information we need for one show.

But then, how would you query for the TV shows that someone has starred in?

Back to my original question: is there something I'm missing here? Handling relational data is something that a lot of applications will need to do, but I can't seem to find a clean solution

1 Answer 1

0

It will be much less work if you go with option 1 in my opinion.

It won't be difficult to learn to use MongoDB, and since MongoDB uses JSON objects and is supported natively by Meteor and all it's packages, it will be much less work.

I advise having a look at the aldeed packages: collection2 and simple-schema to structure your collections. I also advice using the collection-helpers package to help with joins.

If you have a posts collection with name, authorId and content fields, then to get the author of the post, you'd write Meteor.users.findOne(userId).

Hope that clears things up a bit and gets you on your way.

4
  • [reywood:publish-composite][1] is also an important package for dealing with quasi-relational document structures in MongoDB, for example foreign keys. [1]: atmospherejs.com/reywood/publish-composite May 21, 2015 at 5:06
  • None of these help me with querying joins, though. For an example, look at the "Epilogue" of the following article: sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb May 22, 2015 at 14:53
  • You don't need a package to query joins. But collection helpers does help. And there are few articles online hating on mongodb, but a lot of production websites use it without any problems... May 22, 2015 at 15:08
  • I completely understand that a lot of production websites use MongoDB, and I have no problem with MongoDB itself. I am just curious if their data is relational. For example, MongoDB would work really great for storing points on a map, but what about Series -> Seasons -> Episodes -> Actors/Actresses? I'm interested in how someone would query the list of series each actor has starred in. May 23, 2015 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.