$ methods in meteor, why?


#1

Hey guys, I’m brand new to meteor and I’m looking through the tutorial and I am seeing code like this:

Tasks.update(this._id, {
  $set: {checked: ! this.checked}
});

and

return Tasks.find({checked: {$ne: true}}, {sort: {createdAt: -1}});

I’m curious as to why we need to use these dollar functions. What is the reason behind not just passing in an object for the changes?


#2

for example:

Tasks.find({checked: false}

etc etc


#3

They’re part of the Mongo API, and minimongo is designed to expose the Mongo API to the client (making it isomorphic). Also, while it seems like an obvious approach at first, passing in an entire object gets unwieldy with larger records. It’s not uncommon to have records with thousands of fields in production systems.

Welcome to the Meteor forums!