|
| 1 | +- [Mongoid::Scroll](#mongoidscroll) |
| 2 | + - [Compatibility](#compatibility) |
| 3 | + - [Demo](#demo) |
| 4 | + - [The Problem](#the-problem) |
| 5 | + - [Installation](#installation) |
| 6 | + - [Usage](#usage) |
| 7 | + - [Mongoid](#mongoid) |
| 8 | + - [Mongo-Ruby-Driver (Mongoid 5)](#mongo-ruby-driver-mongoid-5) |
| 9 | + - [Indexes and Performance](#indexes-and-performance) |
| 10 | + - [Cursors](#cursors) |
| 11 | + - [Standard Cursor](#standard-cursor) |
| 12 | + - [Base64 Encoded Cursor](#base64-encoded-cursor) |
| 13 | + - [Contributing](#contributing) |
| 14 | + - [Copyright and License](#copyright-and-license) |
| 15 | + |
1 | 16 | # Mongoid::Scroll |
2 | 17 |
|
3 | 18 | [](https://badge.fury.io/rb/mongoid-scroll) |
4 | 19 | [](https://github.com/mongoid/mongoid-scroll/actions/workflows/ci.yml) |
5 | 20 | [](https://gemnasium.com/mongoid/mongoid-scroll) |
6 | 21 | [](https://codeclimate.com/github/mongoid/mongoid-scroll) |
7 | 22 |
|
8 | | -Mongoid extension that enables infinite scrolling for `Mongoid::Criteria`, `Moped::Query` and `Mongo::Collection::View`. |
| 23 | +Mongoid extension that enables infinite scrolling for `Mongoid::Criteria` and `Mongo::Collection::View`. |
9 | 24 |
|
10 | 25 | ## Compatibility |
11 | 26 |
|
12 | | -This gem supports Mongoid 3, 4, 5, 6, 7, Moped and Mongo-Ruby-Driver. |
| 27 | +This gem supports Mongoid 5, 6, and 7. |
13 | 28 |
|
14 | 29 | ## Demo |
15 | 30 |
|
16 | 31 | Check out [shows on artsy.net](http://artsy.net/shows). Keep scrolling down. |
17 | 32 |
|
18 | | -There're also two code samples for Mongoid and Moped in [examples](examples). Run `bundle exec ruby examples/mongoid_scroll_feed.rb`. |
| 33 | +There're also two code samples for Mongoid in [examples](examples). Run `bundle exec ruby examples/mongoid_scroll_feed.rb`. |
19 | 34 |
|
20 | 35 | ## The Problem |
21 | 36 |
|
@@ -78,27 +93,6 @@ Feed::Item.desc(:position).scroll(saved_cursor) do |record, next_cursor| |
78 | 93 | end |
79 | 94 | ``` |
80 | 95 |
|
81 | | -### Moped (Mongoid 3 and 4) |
82 | | - |
83 | | -Scroll a `Moped::Query` and save a cursor to the last item. You must also supply a `field_type` of the sort criteria. |
84 | | - |
85 | | -```ruby |
86 | | -saved_cursor = nil |
87 | | -session[:feed_items].find.sort(position: -1).limit(5).scroll(nil, { field_type: DateTime }) do |record, next_cursor| |
88 | | - # each record, one-by-one |
89 | | - saved_cursor = next_cursor |
90 | | -end |
91 | | -``` |
92 | | - |
93 | | -Resume iterating using the previously saved cursor. |
94 | | - |
95 | | -```ruby |
96 | | -session[:feed_items].find.sort(position: -1).limit(5).scroll(saved_cursor, { field_type: DateTime }) do |record, next_cursor| |
97 | | - # each record, one-by-one |
98 | | - saved_cursor = next_cursor |
99 | | -end |
100 | | -``` |
101 | | - |
102 | 96 | ### Mongo-Ruby-Driver (Mongoid 5) |
103 | 97 |
|
104 | 98 | Scroll a `Mongo::Collection::View` and save a cursor to the last item. You must also supply a `field_type` of the sort criteria. |
@@ -183,11 +177,13 @@ cursor = Mongoid::Scroll::Cursor.from_record(record, { field_type: DateTime, fie |
183 | 177 | Feed::Item.desc(:created_at).scroll(cursor) # Raises a Mongoid::Scroll::Errors::MismatchedSortFieldsError |
184 | 178 | ``` |
185 | 179 |
|
186 | | -### Cursor Encoding |
| 180 | +### Standard Cursor |
| 181 | + |
| 182 | +The `Mongoid::Scroll::Base64EncodedCursor` encodes a value and a tiebreak ID separated by `:`, and does not include other options, such as scroll direction. Take extra care not to pass a cursor into a scroll with different options. |
187 | 183 |
|
188 | | -#### Base64 |
| 184 | +### Base64 Encoded Cursor |
189 | 185 |
|
190 | | -`Mongoid::Scroll::Base64EncodedCursor` can be used instead of `Mongoid::Scroll::Cursor` to generate a base64-encoded string (using RFC 4648) containing all the information needed to rebuild a cursor. |
| 186 | +The `Mongoid::Scroll::Base64EncodedCursor` can be used instead of `Mongoid::Scroll::Cursor` to generate a base64-encoded string (using RFC 4648) containing all the information needed to rebuild a cursor. |
191 | 187 |
|
192 | 188 | ```ruby |
193 | 189 | Feed::Item.desc(:position).limit(5).scroll(Mongoid::Scroll::Base64EncodedCursor) do |record, next_cursor| |
|
0 commit comments