This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor methods are a means by which a client can execute synchronous code on the server as if it was local, and wait for the result before continuing. | |
The important word to note here is "synchronous" - meteor methods are only good "out of the box" if the server-side code it is executing is non-blocking. So what do we do when we need to execute asynchronous code on the server? | |
There are 3 possible approaches: | |
a) Meteor.wrapAsync | |
b) async/await | |
c) fibers/future |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Increment counter: | |
db.analytics.update({"url" : "www.example.com"},{"$inc" : {"pageviews" : 1}}) | |
Adding/Updating a field in a document: | |
db.blog.posts.update({"author.name" : "joe"}, {"$set" : {"author.name" : "joe schmoe"}}) | |
db.positions.update({},{$set:{pos_short_status:"O"}},{upsert:false,multi:true}); | |
db.clients.update({cli_status:"N"},{$set:{cli_status:"A"}},{upsert:false,multi:true}); | |
Removing a field from a document: | |
db.users.update({"name" : "joe"}, ... {"$unset" : {"favorite book" : 1}}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor data subscription | |
how to ensure all data has been delivered to the client before continuing | |
(e.g. in order to initialise a jQuery object that must have all UI elements present) | |
//------------------------------------------------------------------- | |
Template.sample.onCreated(function() { | |
//------------------------------------------------------------------- |