Meteor Collections
@jon_perl
Collections
Server
Client
Publish
Subscribe
Server
Client
Query Examples
$gt
$lt
$or
Mongo Operators
Minimongo limitations
Cursors
Cursors
Modifying Data
Insert
Update
Remove
Bad
Validation & Authorization
Upcoming SlideShare
Loading in …5
×

Meteor Collections

1,034 views

Published on

In

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,034
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Meteor collections / publishes and server methods
  • This will setup a mongo collection on the server -- has the full MongoDB API on the server so you can perform any mongo operation on it.This will setup a minimongo collection on the client – “essentially an in-memory, non-persistent implementation of Mongo in pure JavaScript. It serves as a local cache that stores just the subset of the database that this client is working with. Queries on the client (find) are served directly out of this cache, without talking to the server.”----Can get fancy with collections:- if you need close to real time operations you can pass in null as the connection and it will be a memory basedcollectionpass in a transform function to run on every document -- useful if you want to convert the JSON document to your own typeFor this presentation we will stick to mongo----The client collection will be empty until we setup a publish on the server,and subscribe to it on the client.
  • You can have multiple publish and subscriptions to the same collection. In your view, just make sure to filter the local collection to pull out what you want.You can also reactively subscribe to collections.---The autopublish package is useful for development because it publishes and subscribes to every collection automatically – so don’t forget to remove that before deploying.
  • Query collections with the mongo operators
  • View all the operators here:http://docs.mongodb.org/manual/reference/operator/
  • There are a few limitations on minimongo (operations on client collection).Overcome the limitations by performing these behind server methods, the server collections have access to the full mongo api.See detailed limitations here https://github.com/meteor/meteor/blob/devel/packages/minimongo/NOTES
  • find() returns a cursor and unless you specify otherwise, it will be reactive.---forEach, map, fetch – each can only be called once until you call rewind()Observe and observeChanges
  • Observe allows you to watch for when a query changes.observeChanges is more performant than observe, but only sends the fields that changed
  • The insert function on a collection takes a document.--Update takes a selector (same as find) or an id, and a mongo modifier.If a modifier doesn't contain any $-operators, then it is instead interpreted as a literal document, and completely replaces whatever was previously in the databaseIf you are on the server, you can specify that it should update all matching documents (it defaults to only updating one document).--Remove takes a selector.--Insert, update and remove all have an optional last parameter for a callback that passes an error (if there was one).
  • Validate insert, update, and remove functions to prevent malicious client updates and to enforce validation.Meteor has a check package which makes input validation much easier: http://docs.meteor.com/#matchThere is also a deny function, which is the opposite of the allow function.
  • Meteor Collections

    1. 1. Meteor Collections @jon_perl
    2. 2. Collections
    3. 3. Server Client Publish Subscribe
    4. 4. Server Client
    5. 5. Query Examples $gt $lt $or
    6. 6. Mongo Operators
    7. 7. Minimongo limitations
    8. 8. Cursors
    9. 9. Cursors
    10. 10. Modifying Data
    11. 11. Insert Update Remove Bad
    12. 12. Validation & Authorization

    ×