我使用Heroku的部署我的貓鼬的應用程序,而下面的總收益與本地蒙戈服務器上運行本地主機正確的數據,則返回空結果Heroku的服務器上使用mongolab處理數據庫。
這裏是查詢本身:
let projects = this.models.Project.aggregate(
[
{
$lookup: {from: 'users', localField: 'creator', foreignField: '_id', as: 'creator'}
},
{ $unwind : "$creator" },
{
$project: {
name: 1,
updated: { $dateToString: { format: "%Y-%m-%d", date: "$updated" } },
creator: 1,
description: 1
}
}
]
)
.exec((err, projects) => {
console.log("fetched projects is this:", projects)
res.send(projects);
});
下面是用戶和項目模式:
let userSchema = new Schema({
_id: Schema.Types.ObjectId,
username: String,
password: String,
email: String,
gender: String,
address: String
});
let projectSchema = new Schema({
name: String,
updated: { type: Date, default: Date.now },
creator: {type: Schema.Types.ObjectId, ref: 'User'},
description: String,
issues: [{type: Schema.Types.ObjectId, ref: 'Issue'}]
});
連接到mongolab服務器配置正確和工作,我能夠創建用戶和項目實例有。
我認爲,問題的核心是,文件ID看起來像這樣在我的本地主機:
"_id" : ObjectId("56f1ace9e72b71643070e9a0")
而且像這樣的mongolab:
"_id": {
"$oid": "57030f0972365f0300c56c88"
}
感謝提前任何幫助)
感謝您的信息,我懷疑這樣的事情 – asmodianis