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 find query is passed to the exec callback as the second parameter (ass in your code). The return value you assign to query is the Promise object returned from exec.
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 userAssessments collection instead of userassessments you need to provide that collection name in the mongoose.model call.
So your code should be like this instead:
ANALYZER.userAssessments = mongoose.model(
'userAssessments', userAssessmentsSchema, 'userAssessments');
ANALYZER.analyzeAssessment = function() {
ANALYZER.userAssessments.find({}).exec(function(err, ass) {
if (!err) {
console.log("NO ERROR!");
console.log("QUERY:" + JSON.stringify(ass));
} else {
console.log("ERROR!");
}
});
};