Database Manual / Reference / mongosh Methods

Cursor Methods游标方法

Note

mongosh Methodsmongosh方法

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

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

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 a specific method, including syntax and examples, click on the link to the method's 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 an in-memory sort operation.允许MongoDB在处理内存排序操作时使用磁盘上的临时文件来存储超过100 MB系统内存限制的数据。
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.在查询中附加注释,以允许日志和系统配置文件集合中的可追溯性。
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.返回一个数组,其中包含游标返回的所有文档。
cursor.tryNext()Returns the next element in the iteration if available or else null.返回迭代中的下一个元素(如果可用),否则返回null