I've uploaded a json file to MongoDB Atlas cluster (using mongoimport) and now I'm trying to display the data to localhost using express and mongoose.
I've gotten to a point where I can connect to the cluster but I'm struggling in fetching and displaying the data. Below is the code I have thus far. I'd like to query the database via Nodejs using mongoose as I do on the command line with Mongo shell. What am I missing here?
const express = require("express");
const mongoose = require("mongoose");
const app = express();
// DB config using Mongo Atlas
const uri = require("./config/keys").mongoURI;
// // Connect to Mongo
mongoose
.connect(uri, { useNewUrlParser: true })
.then(() => console.log("MongoDB Connected..."))
.catch(err => console.log(err));
// @route GET
app.get("/", (req, res) => res.send(db.restaurants.find()));
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server started on port ${port}`));