Cursor Methods游标方法

mongo Shell Methods方法

The methods listed on this table of contents page refer to the mongo shell methods, and not to the MongoDB Node.js driver (or any other driver) methods. 此目录页上列出的方法指的是mongo shell方法,而不是MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

These methods modify the way that the underlying query is executed.这些方法修改了基础查询的执行方式。

Note

For details on specific methods, including syntax and examples, click on the specific method to go to its reference page.有关特定方法的详细信息,包括语法和示例,请单击特定方法以转到其参考页。

Name名称Description描述
cursor.addOption() Adds special wire protocol flags that modify the behavior of the query.添加修改查询行为的特殊wire协议标志。
cursor.allowDiskUse() Allows MongoDB to use temporary files on disk to store data exceeding the 100 megabyte system memory limit while processing a blocking sort operation.允许MongoDB在处理阻塞排序操作时使用磁盘上的临时文件存储超过100 MB系统内存限制的数据。
cursor.allowPartialResults() Allows db.collection.find() operations against a sharded collection to return partial results, rather than an error, if one or more queried shards are unavailable.如果一个或多个查询的分片不可用,则允许对分片集合执行db.collection.find()操作以返回部分结果,而不是错误。
cursor.batchSize() Controls the number of documents MongoDB will return to the client in a single network message.控制MongoDB在单个网络消息中返回到客户端的文档数。
cursor.close() Close a cursor and free associated server resources.关闭光标并释放关联的服务器资源。
cursor.isClosed() Returns true if the cursor is closed.如果光标已关闭,则返回true
cursor.collation() Specifies the collation for the cursor returned by the db.collection.find().指定db.collection.find()返回的游标的排序规则。
cursor.comment() Attaches a comment to the query to allow for traceability in the logs and the system.profile collection.将注释附加到查询,以允许在日志和system.profile集合中进行跟踪。
cursor.count() Modifies the cursor to return the number of documents in the result set rather than the documents themselves.修改光标以返回结果集中的文档数,而不是文档本身。
cursor.explain() Reports on the query execution plan for a cursor.报告游标的查询执行计划。
cursor.forEach() Applies a JavaScript function for every document in a cursor.为游标中的每个文档应用JavaScript函数。
cursor.hasNext() Returns true if the cursor has documents and can be iterated.如果游标具有文档并且可以迭代,则返回true
cursor.hint() Forces MongoDB to use a specific index for a query.强制MongoDB对查询使用特定索引。
cursor.isExhausted() Returns true if the cursor is closed and there are no objects remaining in the batch.如果光标已关闭且批处理中没有剩余对象,则返回true
cursor.itcount() Computes the total number of documents in the cursor client-side by fetching and iterating the result set.通过获取并迭代结果集,计算游标客户端中的文档总数。
cursor.limit() Constrains the size of a cursor’s result set.约束光标结果集的大小。
cursor.map() Applies a function to each document in a cursor and collects the return values in an array.将函数应用于游标中的每个文档,并在数组中收集返回值。
cursor.max() Specifies an exclusive upper index bound for a cursor. 指定游标的独占索引上限。For use with cursor.hint()cursor.hint()一起使用
cursor.maxTimeMS() Specifies a cumulative time limit in milliseconds for processing operations on a cursor.指定处理光标上的操作的累积时间限制(以毫秒为单位)。
cursor.min() Specifies an inclusive lower index bound for a cursor. 指定游标的包含性索引下限。For use with cursor.hint()cursor.hint()一起使用
cursor.next() Returns the next document in a cursor.返回光标中的下一个文档。
cursor.noCursorTimeout() Instructs the server to avoid closing a cursor automatically after a period of inactivity.指示服务器避免在一段时间不活动后自动关闭光标。
cursor.objsLeftInBatch() Returns the number of documents left in the current cursor batch.返回当前游标批中剩余的文档数。
cursor.pretty() Configures the cursor to display results in an easy-to-read format.将光标配置为以易于阅读的格式显示结果。
cursor.readConcern() Specifies a read concern for a find() operation.指定find()操作的读取关注点
cursor.readPref() Specifies a read preference to a cursor to control how the client directs queries to a replica set.指定游标的读取首选项,以控制客户端如何将查询定向到副本集
cursor.returnKey() Modifies the cursor to return index keys rather than the documents.修改光标以返回索引键而不是文档。
cursor.showRecordId() Adds an internal storage engine ID field to each document returned by the cursor.将内部存储引擎ID字段添加到光标返回的每个文档中。
cursor.size() Returns a count of the documents in the cursor after applying skip() and limit() methods.在应用skip()limit()方法后,返回游标中文档的计数。
cursor.skip() Returns a cursor that begins returning results only after passing or skipping a number of documents.返回仅在传递或跳过多个文档后才开始返回结果的游标。
cursor.sort() Returns results ordered according to a sort specification.返回根据排序规范排序的结果。
cursor.tailable() Marks the cursor as tailable. Only valid for cursors over capped collections.将光标标记为可裁剪。仅对上限集合上的游标有效。
cursor.toArray() Returns an array that contains all documents returned by the cursor.返回包含光标返回的所有文档的数组。