Collections exteneded with PeerDB package for denormalized approach to data storage in MongoDB. Requires coffeescript and peerdb packages.
Last active
January 2, 2016 08:49
-
-
Save aaronthorp/8278598 to your computer and use it in GitHub Desktop.
Meteor.js Collection with PeerDB integration. @aaronthorp
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
| @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
