By default, MongoDB will automatically close a cursor when the client has exhausted all results in the cursor. 默认情况下,当客户端耗尽游标中的所有结果时,MongoDB将自动关闭游标。However, for capped collections you may use a Tailable Cursor that remains open after the client exhausts the results in the initial cursor. 但是,对于封顶集合,您可以使用一个可裁剪的游标,该游标在客户端耗尽初始游标中的结果后保持打开状态。Tailable cursors are conceptually equivalent to the 可定制游标在概念上等同于带有-f选项的tail
Unix command with the -f
option (i.e. with “follow” mode). tail
Unix命令(即带有“follow”模式)。After clients insert new additional documents into a capped collection, the tailable cursor will continue to retrieve documents.在客户端将新的附加文档插入到一个有上限的集合中之后,可裁剪游标将继续检索文档。
Use tailable cursors on capped collections that have high write volumes where indexes aren’t practical. 在索引不实用的写容量较大的封顶集合上使用可定制游标。For instance, MongoDB replication uses tailable cursors to tail the primary’s oplog.例如,MongoDB复制使用可定制的游标来跟踪主服务器的oplog。
Note
If your query is on an indexed field, do not use tailable cursors, but instead, use a regular cursor. 如果查询位于索引字段上,请不要使用可定制的游标,而是使用常规游标。Keep track of the last value of the indexed field returned by the query. 跟踪查询返回的索引字段的最后一个值。To retrieve the newly added documents, query the collection again using the last value of the indexed field in the query criteria, as in the following example:要检索新添加的文档,请使用查询条件中索引字段的最后一个值再次查询集合,如下例所示:
Consider the following behaviors related to tailable cursors:考虑下列与可裁剪游标有关的行为:
A dead cursor has an id of 无效游标的id为0
.0
。
See your driver documentation for the driver-specific method to specify the tailable cursor.有关指定可剪裁游标的特定于驾驶员的方法,请参阅驱动程序文档。