Docs HomeMongoDB Manual

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 Server版本的文档:

mongo shell v4.4

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 a blocking sort operation.允许MongoDB在处理阻塞排序操作时使用磁盘上的临时文件来存储超过100兆字节系统内存限制的数据。
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.将注释附加到查询,以允许在日志和系统配置文件集合中进行跟踪。
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,则返回迭代中的下一个元素。