I currently have a collection named Consumer_Complaints sitting in a mongoDB database called consumer_Complaints (sorry for making that confusing).
I can access the Consumer_Complaints collection via the mongo shell, but I am unable to access it in my application. I am currently using express.
Here is my code(Updated):
var mongoose = require("mongoose");
//open connection to consumer_Complaints database
mongoose.connect('mongodb://localhost/consumer_Complaints')
//send error if connection fails
mongoose.connection.on('error', console.error.bind(console, 'connection error:' ));
var Schema = mongoose.Schema;
var complaintSchema = new Schema({
complaint_ID: String,
product: String,
sub_Product: String,
issue: String,
sub_Issue: String,
state: String,
zip_Code: String,
submitted_Via: String,
date_Received: String,
date_sent_to_Company: String,
company: String,
company_Response: String,
timely_Response: String,
consumer_Disputed: String,
});
complaintSchema.set('collection', 'Consumer_Complaints');
var model = mongoose.model("Model", complaintSchema)
model.find({}, function (err, results) {
res.json(results);
console.log(results);//Your Json result
});
Previous Answer- Found Here This seems to be what I want, but the syntax used is different than what I see in the mongoose documents, and when I try to replicate this, I get the following error.
"TypeError: Cannot call method 'find' of undefined"
Any help clarifying the top answer in the linked post, or figuring out what I'm doing wrong would be greatly appreciated!