File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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 ( )
You can’t perform that action at this time.
0 commit comments