From Discover Meteor: find() returns a cursor, which is a reactive data source.
Data from reactive sources will be updated automatically to track changes in the data used to generate it. Cursors are derived from specific sources:
- Session variables
- Database queries on Collections
- Meteor.status
- The ready() method on a subscription handle
- Meteor.user
- Meteor.userId
- Meteor.loggingIn
> Posts.find()
LocalCollection.Cursor {collection: LocalCollection, sorter: null, _selectorId: undefined, matcher: Minimongo.Matcher, skip: undefined…}
_selectorId: undefined
_transform: null
collection: LocalCollection
cursor_pos: 0
db_objects: null
fields: undefined
limit: undefined
matcher: Minimongo.Matcher
reactive: true
skip: undefined
sorter: null
__proto__: ObjectCursors are not query snapshots. They are query snapshot containers — the contents of which are updated by changes to the underlying data. To interact with the data contained in a cursor, we can use fetch() to transform the cursor into an array.
> Posts.find().fetch()
[
Object
_id: "z4z36DFCaGr8Ptuqd"
title: "The Way We Live Now"
author: "Anthony Trollope"
__proto__: Object
...
]Meteor can iterate over a cursor without first converting it to an array, but in order to interact with the data directly, you must first use fetch(), map(), or forEach(). For more cursor fun, checkout the Meteor docs.
Awesome.