I am trying to get node.js to write to the console the data in the table, my other tables work.
Whenever I try I get the following output:
NO ERROR!
QUERY:{"emitted":{"complete":[[]]},"_events":{}}
Am I missing something in the Schema definition?
Any help would be appreciated.
– Eric
The following is from the mongo shell :
> db.userAssessments.find({})
{ "accountId" : "509683edcb884b0000000001", "created" : ISODate("2013-01-12T03:31:20.723Z"), "_id" : ObjectId("50f0d9084469766bb7000001") }
This is my js:
var userAssessmentsSchema = new mongoose.Schema({
accountId : String,
created : Date,
id: String
});
ANALYZER.userAssessments = mongoose.model('userAssessments', userAssessmentsSchema);
ANALYZER.analyzeAssessment = function() {
var query = ANALYZER.userAssessments.find({}).exec(function(err, ass) {
if (!err) {
console.log("NO ERROR!");
console.log("QUERY:" + JSON.stringify(query));
} else {
console.log("ERROR!");
}
});
};
The result of the
findquery is passed to theexeccallback as the second parameter (assin your code). The return value you assign toqueryis thePromiseobject returned fromexec.UPDATE
Your other problem is that Mongoose pluralizes and lower-cases the model name to derive the collection name if you don’t provide one. To make it use the
userAssessmentscollection instead ofuserassessmentsyou need to provide that collection name in themongoose.modelcall.So your code should be like this instead: