herteby:collection-methods

v0.1.0Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Collection Methods

Streamlined collection updates for Meteor, combining collection-helpers with Meteor methods, plus automatic logging.

meteor add herteby:collection-methods

Example

1Todos = new Mongo.Collection('todos')
2
3Todos.methods({
4	markDone(){
5		if(this.doc.ownerId !== this.user._id){
6			throw new Error('Authorization denied')
7		}
8		if(_.find(this.doc.tasks, task => !task.done)){
9			console.log('all tasks are not done')
10		} else {
11			Todos.update(this.doc._id, {$set:{done:{user:this.user._id, date:new Date()}}})
12		}
13	},
14	setTitle$(title){ //adding $ to the name means that multiple calls within one minute will be logged as one. Useful for text fields.
15		if(this.doc.ownerId !== this.user._id){
16			throw new Error('Authorization denied')
17		}
18		Todos.update(this.doc._id, {$set:{title}})
19	}
20})