Created
January 29, 2020 21:37
-
-
Save skobba/9cd0ec450220ecba9fc3d62e0c6df44b to your computer and use it in GitHub Desktop.
mongodb list collection
This file contains hidden or 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
| import { MongoClient } from 'mongodb'; // eslint-disable-line import/no-extraneous-dependencies | |
| const authSource = 'demo'; | |
| const url = `mongodb://${process.env.MONGO_USERNAME}:${process.env.MONGO_PASSWORD}@${process.env.MONGO_HOSTNAME}:${process.env.MONGO_PORT}/${authSource}?authSource=demo&authMechanism=SCRAM-SHA-1`; | |
| MongoClient.connect( | |
| url, | |
| { useNewUrlParser: true, useUnifiedTopology: true }, | |
| function(err, db) { | |
| if (err) throw err; | |
| const dbo = db.db('demo'); | |
| dbo.collection('clients').findOne({}, function(err, result) { | |
| if (err) throw err; | |
| console.log(result.firstName); // eslint-disable-line no-console | |
| db.close(); | |
| }); | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment