Last Updated: February 25, 2016
·
3.697K
· haihappen

minimongoid or: How I learned to love Meteor

TL;DR

minimongoid is a Mongoid clone for your Meteor apps, kinda. Check it out on https://github.com/haihappen/minimongoid!

My new love

Back in mid 2012, when I heard about Meteor the first time, I was mind-blown. It gave me the exact the same goosebumps I had back in school after seeing @dhh's Rails screencast. Definitely a good feeling :) and a sign for myself to dig deeper into Meteor. Now it's 2013, Meteor <strike>0.5.3 was released yesterday</strike> 0.5.4 was just released today and I have played with it for quite a while now.

… but we still have differences

The biggest downside so far with Meteor is the lack of a proper model class. It's totally okay to mess around with collections directly if you have 1 or 2 collections. Even 5 should work. But my average app has definitely more than that. And my current playground app, which will talk to bunch of 3rd party services in the future, has already more than 5. (Each service needs its own API calls and parsing of data.)

… so I tried, and voila, I'm in love again

class User extends Minimongoid
  @_collection: new Meteor.Collection('users')

  isValid: ->
    @attributes.name.match /John|Jane/

User.create name: 'John'
User.create name: 'Jane'
User.create name: 'Frank' # not saved, because invalid

User.all() => [User, User]

Yes, you guessed it already, the name is based on Meteor's own minimongo.
Be sure to checkout the implementation and the tests for usage and more infos.

One does not simply write CoffeeScript

Well as a Rubist you do! I even did this, Rubists will love me, all other will burn me :)

User.new name: 'John' # => User 

Meteor will maybe ship with some model class in the future, but until then I will use this approach. Feel free to share your thoughts and ideas :)

4 Responses
Add your response

Very nice approach!

over 1 year ago ·

I like where you're going with this. Question: what if you want to use this class on both the client side and the server side? How would you solve this problem?

over 1 year ago ·

@sslotsky once included the class should be available both on server and client side automagically.

over 1 year ago ·

Does your implementation works with {{#each}} where it only updates changed parts?

over 1 year ago ·