cursor.
toArray
()¶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驱动程序文档。
The 方法返回一个数组,该数组包含游标中的所有文档。toArray()
method returns an array that contains all the documents from a cursor. The method iterates completely the cursor, loading all the documents into RAM and exhausting the cursor.该方法完全迭代游标,将所有文档加载到RAM中并耗尽游标。
Returns: |
---|
Consider the following example that applies 考虑下面的示例,将toArray()
to the cursor returned from the find()
method:toArray()
应用到从find()
方法返回的游标:
The variable 变量allProductsArray
holds the array of documents returned by toArray()
.allProductsArray
保存toArray()
返回的文档数组。