Cursor Methods游标方法

Note注意
mongosh Methods

The methods listed on this table of contents page are mongosh methods. 目录页上列出的方法是mongosh方法。This is not the documentation for Node.js or other programming language specific driver methods.不是Node.js或其他编程语言特定驱动程序方法的文档。

In most cases, mongosh methods work the same way as the legacy mongo shell methods. 在大多数情况下,mongosh方法的工作方式与传统mongoShell方法相同。However, some legacy methods are unavailable in mongosh.但是,一些传统方法在mongosh中不可用。

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:有关传统mongoShell文档,请参阅相应MongoDB服务器版本的文档:

For MongoDB API drivers, refer to the language specific MongoDB driver documentation.有关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.添加修改查询行为的特殊有线协议标志。
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.maxAwaitTimeMS()Specifies a limit in milliseconds to wait for the next query result update.指定等待下一次查询结果更新的毫秒限制。
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.返回包含游标返回的所有文档的数组。
←  db.collection.validate()cursor.addOption() →