I am trying to create an api which would fetch data from local mongodb
I have added dependencies , created the database schema and the name of the collection, and connected to MongoDB:
var cors = require('cors');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var app = express();
var supportSchema = new Schema({
_id: {type:ObjectId, auto: true },
UserId: { type:String, required: true },
Name: String
}, {
collection: 'abc'
});
var SupportModel = mongoose.model('Model', supportSchema);
mongoose.connect('mongodb://localhost:27017/dbName');
Now added routes in the same .js file that we will use to query the data:
app.get('/find/:query', function(req, res) {
let envId = request.params.envId;
SupportModel.find({environmentId: envId}, {}, function(err) {
if (err) {
console.log(err);
}
})
})
I am getting an error Route GET:/find/123 not found