这是我的模特
const translateSchema = mongodb.Schema([{
floor: {
type: String
},
view: {
type: String
}
}]);
const TranslateModel = module.exports = mongodb.model('TranslateModel', translateSchema, 'translation');
module.exports.getTranslate = function(parms, callback){
TranslateModel.aggregate([
{
$match:{$and:[{property:"ATL-D406"},{language:"gb"}]}
},
{
$unwind:"$texts"
},
{
$project:{"_id":0,"floor":"$texts.floor","view":"$texts.view"}
}
],function(err, result) {
if (err) return handleError(err);
console.log('Mongo Result 1: ' + result);
console.log("Mongo Result 2: " + JSON.stringify(result, null, 4));
callback(result);
});
}
聚合工作正常,在控制台我得到了这个:
Mongo Result1: [object Object]
Mongo Result2: [
{
"floor": "4th floor",
"view": "Pool View (island)"
}
]
所以字段在那里,为什么它不适合我的Schema?
当我尝试使用回调发送回来(结果);我收到这个错误:
错误:未捕获,未指定"错误"事件。 ([object Object])
当我使用getOne时,一切正常,我得到结果并可以返回等等。我没看到什么?