@@ -170,82 +170,7 @@ The ``tail`` function performs the following actions:
170170 - Loop through the outer ``while (1)`` loop to re-query with the new query
171171 condition and repeat.
172172
173- JavaScript Example
174- ------------------
173+ .. seealso::
175174
176- The JavaScript example uses a tailable cursor to output the results
177- from a query of a capped collection named ``myCappedCollection``. To
178- periodically check for new data, the ``cursor->hasNext()`` statement is
179- inside a loop:
180-
181- .. code-block:: javascript
182-
183- var coll = db.myCappedCollection;
184-
185- var startDoc = coll.find().hint( { '$natural': 1 } ).limit(1).next();
186- var lastValue = startDoc['insertDate'];
187- printjson(startDoc)
188-
189- while (1) {
190-
191- var cursor = coll.find( { 'insertDate' : { '$gt' : lastValue } } ).hint( { '$natural': 1 } );
192-
193- cursor.addOption( DBQuery.Option.tailable );
194-
195- cursor.addOption( DBQuery.Option.awaitData );
196-
197- while ( cursor.hasNext() ) {
198- var doc = cursor.next();
199- lastValue = doc['insertDate'];
200- printjson(doc);
201- }
202- }
203-
204- The example performs the following actions:
205-
206- - Query the capped collection to access the first document inserted.
207- The query uses the :method:`hint() <cursor.hint()>` method to ensure
208- the use of the insertion order.
209-
210- - Initialize the ``lastValue`` variable to hold the last accessed value
211- of the unindexed field ``insertDate``. Newly added documents contain
212- increasing values for the ``insertDate`` field.
213-
214- - In an outer ``while (1)`` loop,
215-
216- - Query the capped collection for documents with the field
217- ``insertDate`` greater than the ``lastValue``. The query uses the
218- :method:`hint() <cursor.hint()>` method to ensure that the
219- insertion order is used.
220-
221- - Specify that the returned cursor should be a tailable cursor:
222-
223- .. code-block:: javascript
224-
225- cursor.addOption( DBQuery.Option.tailable );
226-
227- See your :doc:`driver documentation </applications/drivers>` for
228- the driver-specific method to specify a tailable cursor.
229-
230- - Specify that the cursor should block for a few seconds to wait for
231- data:
232-
233- .. code-block:: javascript
234-
235- cursor.addOption( DBQuery.Option.awaitData );
236-
237- See your :doc:`driver documentation </applications/drivers>` for
238- the driver-specific method to specify that the cursor should wait
239- for data.
240-
241- - In an inner ``while (cursor.hasNext())`` loop,
242-
243- - retrieve the document,
244-
245- - update the ``lastValue`` variable,
246-
247- - print the document,
248-
249- - and loop to recheck for more documents.
250-
251- - If there are no more documents, repeat the outer loop.
175+ `Detailed blog post on tailable cursor
176+ <http://shtylman.com/post/the-tail-of-mongodb>`_
0 commit comments