cursor.toArray()Importante
Método mongosh
This page documents a
mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.Para drivers de API do MongoDB, consulte a documentação do driver do MongoDB específica da linguagem.
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.Retorna: Uma array de documentos.
Consider the following example that applies toArray() to the cursor returned from the find() method:
var allProductsArray = db.products.find().toArray(); if (allProductsArray.length > 0) { printjson (allProductsArray[0]); }
The variable allProductsArray holds the array of documents returned by toArray().
Compatibilidade
Esse método está disponível em implantações hospedadas nos seguintes ambientes:
- MongoDB Atlas: o serviço totalmente gerenciado para implantações do MongoDB na nuvem
Observação
Este comando é aceito em todos os clusters do MongoDB Atlas. Para obter informações sobre o suporte do Atlas a todos os comandos, consulte Comandos não suportados.
MongoDB Enterprise: a versão autogerenciada e baseada em assinatura do MongoDB
MongoDB Community: uma versão com código disponível, de uso gratuito e autogerenciada do MongoDB