What is Meteor.js?

Meteor is a full-stack framework written in Javascript. It's built on top of node.js for the server-side code and is compatible with MongoDB only at the moment. Yes, that's right, you can code away all you want in the same framework for both client and server-side work.

Why should I care about the Meteor.users collection?

Well, hold your horses, I haven't even told you what makes up the collection. The Meteor.users collection holds data about users that have logged into your web application. Since Meteor uses a Mongo databases on the back-end, it uses almost identical syntax to access and manipulate cached collections on the client side. Very briefly,

  • Meteor.user() returns the current person that invokes whatever is using Meteor.user(), in object form.
    • By default the server publishes (which we can get more into in another article) username, emails and profiles that are written by the user on log-in. What information is published about a user can be modified on the server-side.
  • Meteor.users returns a cursor to the cached MiniMongo collection.
    • I know what you're thinking, 'John! I really want to iterate over this users collection and perform some operations but I can't in this format!', to which I say Meteor.users.find().fetch() is the answer you seek! That will return an array ready to be iterated over.

If this syntax looks familiar to you, then congratulations you know something about MongoDB. The find and fetch methods are both commonly used when accessing and manipulating data in MongoDB.

Adding and manipulating the user record

One pain-point that I dealth with in my most recent Meteor project was accessing and modifying user data.

The first way to add data to the user object is by adding it on instantiation, when the user creates an account. By using the Accounts.onCreateUser method in your server-side code, you use dot-notation to set default properties such as the score, just be sure you return user at the end of the method.

Another easy way to add information to the user object is by pulling in outside libraries, my team used mizzao's fantastic user-status Meteor package which can be found here. This package will track the status of a user, whether or not they are idle or logged in/out.

I'm sure there are other ways to manipulate user data, but these are the ways my team and I used when we created Cards Against Sobriety, an online version of Cards Against Humanity. Thanks for reading this quick post of Meteor.js, I'll probably be diving deeper into it in later articles!

p.s. If you're interested in Meteor check out my teammate Kate's blog post on the back-end here!


Hack Reactor , Javascript , Meteor , Meteor.js , Users , Collections , User

About the author
comments powered by Disqus