-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
114 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/////// MONGODB | ||
const url = require("url"); | ||
const MongoClient = require("mongodb").MongoClient; | ||
|
||
// Create cached connection variable | ||
let cachedDb = null; | ||
|
||
// a function for connecting to MOngoDB | ||
// taking a single parameter of the connection string | ||
|
||
async function connectToDatabase(uri) { | ||
//if the database connection is cached , | ||
//use it instead of creating a new connection | ||
if (cachedDb) { | ||
return cachedDd; | ||
} | ||
//if no connection is cached, create a new one | ||
const client = await MongoClient.connect(uri, { useNewUrlParser: true }); | ||
|
||
//seect the database through the connection, | ||
//using the database ath of the connection string | ||
const db = await client.db(url.parse(uri).pathname.substr(1)); | ||
|
||
// cache the database connection and return the connection | ||
cachedDb = db; | ||
return db; | ||
} | ||
|
||
exports.listSessions = async function(req, res) { | ||
console.log("list all sessions"); | ||
var athleteId = req.params.athleteId; | ||
console.log("athledId = ", athleteId); | ||
console.log(process.env.MONGODB_URI); | ||
const db = await connectToDatabase(process.env.MONGODB_URI); | ||
|
||
//Select sessions collection | ||
const sessionsCollection = await db.collection("sessions"); | ||
//select all the sessions | ||
const allSessions = await sessionsCollection.find({}).toArray(); | ||
|
||
//respond with the array created | ||
// as a json | ||
res.status(200).json(allSessions); | ||
}; | ||
|
||
exports.addSessions = async function(req, res) { | ||
res.status(200); | ||
}; |
This file contains 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
This file contains 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
6cfee66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://now-spin-qfxcsm227.now.sh to the following aliases: