Last active
April 15, 2017 00:17
-
-
Save oieduardorabelo/4fff511490c6be6ca0ae5bd51bc6ae9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongodb = require('mongodb'); | |
test(); | |
async function test() { | |
const db = await mongodb.MongoClient.connect('mongodb://localhost:27017/test'); | |
await db.collection('Movies').drop(); | |
await db.collection('Movies').insertMany([ | |
{ name: 'Enter the Dragon' }, | |
{ name: 'Ip Man' }, | |
{ name: 'Kickboxer' } | |
]); | |
// Não usamos `await` aqui, ao invés disso, recebemos o Cursor | |
const cursor = db.collection('Movies').find(); | |
// Usamos `next()` e `await` para iterar todos os valores do Cursor | |
for (let doc = await cursor.next(); doc != null; doc = await cursor.next()) { | |
console.log(doc.name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment