You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54Lines changed: 54 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,60 @@ Installation
23
23
meteor add peerlibrary:reactive-mongo
24
24
```
25
25
26
+
Invalidating computations on Ordered vs. Unordered cursors
27
+
------------
28
+
In Meteor, there's a concept of `ordered` cursors. If a cursor is `ordered`, then when the order of the documents in the result set changes, the computation will be invalidated and the `autorun` will re-run.
29
+
30
+
By default, this package will use an ordered cursor if a `sort` is present in the query. If no `sort` is specified, it will use an unordered cursor.
31
+
32
+
To override the defualt functionality, you can explicitly force or un-force `ordered` by passing an `ordered` option to your `find`:
A common use case for server autoruns is using a `findOne` to do a reactive join. Meteor's server-side `findOne` is a `find(selector, { limit: 1 }).fetch()[0]`[under the hood](https://github.com/meteor/meteor/blob/devel/packages/mongo/mongo_driver.js#L784). [Because Meteor Oplog does not support](https://galaxy-guide.meteor.com/apm-optimize-your-app-for-oplog.html#Limit-Without-Sort)`limit` without `sort`, calling `Collection.findOne(someId)` in a server autorun will default to using polling.
61
+
62
+
63
+
If you'd like queries inside a server autorun to use Oplog, you'll need to specify a sort for your `findOne`**and** pass `ordered: false` to use unordered cursor:
64
+
65
+
```
66
+
// Server code
67
+
68
+
// Will use oplog since it has sort, limit, and is unordered
0 commit comments