Skip to content

Instantly share code, notes, and snippets.

@aaronthorp
Last active January 2, 2016 08:49
Show Gist options
  • Save aaronthorp/8278598 to your computer and use it in GitHub Desktop.
Save aaronthorp/8278598 to your computer and use it in GitHub Desktop.
Meteor.js Collection with PeerDB integration. @aaronthorp

Meteor.js Collections with PeerDB and CoffeeScript

Collections exteneded with PeerDB package for denormalized approach to data storage in MongoDB. Requires coffeescript and peerdb packages.

Support us via Gittip

@ClientCollection = new Meteor.Collection("clients",
transform: (document) ->
new Client(document)
)
@AddressCollection = new Meteor.Collection("address",
transform: (document) ->
new Address(document)
)
class @User extends Document
@Meta
name: 'User'
# Specifying collection directly
collection: Meteor.users
class @Address extends Document
@Meta
name: 'Address'
class @Client extends Document
# Other fields:
# body
# add custom fields here
friend_count: ->
return @friends.length if @friends
0
@Meta
name: 'Client'
fields:
# We can reference other document
address: @ReferenceField Address, ['address']
owner: @ReferenceField User, ['profile.firstName', 'profile.lastName']
friends: [@ReferenceField User, ['profile.firstName', 'profile.lastName']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment