In my mongodb i already had a collection and document
Now, i want to use this collection in my node-js using mongoose. how we do this.
const mongoose = require("mongoose");
const schema = mongoose.Schema;
const adminLogin = new schema({
name: { type: String, required: true },
password: { type: String, required: true }
})
module.exports = mongoose.model("adminDetails", adminLogin)
while doing this it is creating new collection. Unable to use the existing collection.
CodePudding user response:
- At first you need to make a GET method Router in your jsFile.
like this
app.get("/mainData", async (req, res) => {
const menuInfo = await Nutrients.find({});
res.json(menuInfo);
});
- You can set and use VSCode extension "thunderClient"!
like this
In this above picture the structure of dB, one collection having 5 collections. I'm trying to use adminDetails collection. But, after running the above code it is creating the new collection. But, i'm unable to use the existing collection. FYI: