我一直在关注tutorial on how to use $Lookup
in MongoDB,但是使用该代码时却崩溃了,我不知道为什么(具体错误是“ 404 Not Found”,但是当{{1} }已删除,没有错误)。
这就是我所拥有的:
$Lookup
资产架构
db.assets.aggregate([{
$lookup: {
from: "users",
localField: "currentUser",
foreignField: "emplyID",
as: "IDtoNames"
},
$project: {
"assetID": "$assets.assetID",
"firstName": "$users.name.first",
"lastName": "$users.name.last",
"assetType": "$assets.assetType"
},
}
用户架构
var assetSchema = new mongoose.Schema({
assetID: {
type: Number,
unique: true
},
assetType: String,
status: String,
currentUser: String,
为什么我使用 var userSchema = new mongoose.Schema({
emplyID: {
type: Number,
unique: true,
required: true
},
name: {
first: {
type: String,
required: true
},
middle: String,
last: {
type: String,
required: true
}
会使应用程序崩溃?