-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·32 lines (27 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node
require('dotenv').config();
const { MongoClient } = require('mongodb');
const connectionString = `mongodb://${process.env.MONGODB_USERNAME}:${process.env.MONGODB_PASSWORD}@${process.env.MONGODB_HOST}:${process.env.MONGODB_PORT}`;
// Normally, don't do this
console.debug(`'Connection string: ${connectionString}'`);
console.log('Connecting to database');
const client = new MongoClient(connectionString);
async function run() {
try {
const database = client.db(process.env.MONGODB_DATABASE);
const departments = database.collection('departments');
// Query for a movie that has the title 'Back to the Future'
const query = {};
console.log('Running find...');
const departmentDocsCursor = await departments.find(query);
console.log('Printing results...');
for await (const doc of departmentDocsCursor) {
console.log(doc);
}
console.log('Done.');
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);