On this page本页内容
cursor.
forEach
(function)¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
Iterates the cursor to apply a JavaScript 迭代游标,将JavaScript函数应用于游标中的每个文档。function
to each document from the cursor.
The forEach()
method has the following prototype form:forEach()
方法的原型形式如下:
The forEach()
method has the following parameter:forEach()
方法具有以下参数:
function |
JavaScript | <function> signature includes a single argument that is passed the current document to process.<function> 签名包含一个参数,该参数通过当前文档传递给进程。 |
The following example invokes the 以下示例对forEach()
method on the cursor returned by find()
to print the name of each user in the collection:find()
返回的游标调用forEach()
方法,以打印集合中每个用户的名称:
See also参阅
cursor.map()
for similar functionality.用于类似的功能。