Skip to content

Commit d05c072

Browse files
committed
Extract data from MongoDB 🐻
1 parent a06e66d commit d05c072

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

node/app.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { MongoClient } = require('mongodb')
2+
3+
const username = 'dataength'
4+
const password = 'xyz'
5+
const hostName = 'cluster0.xyz.mongodb.net'
6+
const dbName = 'sample_airbnb'
7+
const collectionName = 'listingsAndReviews'
8+
9+
const run = async () => {
10+
const uri = `mongodb+srv://${username}:${password}@${hostName}/${dbName}?retryWrites=true&w=majority`
11+
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true })
12+
await client.connect()
13+
14+
const collection = client.db(dbName).collection(collectionName)
15+
16+
const query = {}
17+
const options = {}
18+
const cursor = collection.find(query, options)
19+
20+
if ((await cursor.count()) === 0) {
21+
console.log('No documents found!');
22+
}
23+
24+
await cursor.forEach(result => {
25+
console.log(result)
26+
})
27+
28+
await client.close()
29+
}
30+
31+
run()

0 commit comments

Comments
 (0)