Skip to content

Commit b905e5e

Browse files
committed
init Github
0 parents  commit b905e5e

File tree

4 files changed

+497
-0
lines changed

4 files changed

+497
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

index.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const mongodb = require('mongodb');
2+
const express = require('express');
3+
4+
const app = express();
5+
6+
let db;
7+
const connectionOptions = { poolSize: process.env.MONGO_POOLSIZE || 1 };
8+
9+
mongodb.MongoClient.connect('mongodb://localhost:27017/test', connectionOptions, function(err, database) {
10+
if (err) throw err;
11+
db = database.db('test');
12+
// create some documents required for demonstration
13+
db.collection('test').insertOne();
14+
15+
app.listen(process.env.PORT || 3000, function() {
16+
console.log(`Express.js server up.`);
17+
});
18+
});
19+
/*
20+
For demonstration purposes, this route will always return slowly due to an intentionally slow query (5seconds per document)
21+
*/
22+
app.get('/slow', function (req, res) {
23+
db.collection('test').find({'$where': 'sleep(5000) || true'}).toArray(function(err, cursor) {
24+
return res.json({"docCount": 'docs'});
25+
});
26+
27+
});
28+
/*
29+
This route should always return quickly
30+
*/
31+
app.get('/fast', function (req, res) {
32+
db.collection('test').countDoucments({}, function(err, count) {
33+
return res.json({'documentCount': count});
34+
});
35+
36+
});

0 commit comments

Comments
 (0)