Last active
April 5, 2020 18:08
-
-
Save vladi-strilets/8dc29cef59b3cea3a64647ffb5ce2bc3 to your computer and use it in GitHub Desktop.
mongodb client handler node.js #2
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
// routes/someroute.js | |
const express = require("express"); | |
const router = express.Router(); | |
const getClient = require("../db"); | |
router.get("/", async (req, res) => { | |
try { | |
const client = await getClient(); | |
const db = client.db("YOUR_BD_NAME"); | |
const collection = db.collection("YOUR_COLLECTION_NAME"); | |
collection.find({}).toArray((err, data) => { | |
res.send(data); | |
} | |
} catch (err) { | |
res.status(500).send('Something broke!'); | |
} | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment