我是猫鼬的新手,但我无法解决这个问题。我正在尝试在节点上的路由中显示用户和财务状况,但仅显示用户,而与财务状况无关。
代码类似于:
const financeSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User'
},
website: {
type: String,
require: true,
},
deposits: {
type:Number,
default: 0
},
totalwith: {
type: Number,
default: 0
}, {
timestamps: true
})
const Finance = mongoose.model('finance', financeSchema)
2 different files
const userSchema = new mongoose.Schema({
name: {
type: String,
required: true,
trim: true
},
finance: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Finance'
},
phone: {
type: Number,
}
const User = mongoose.model('User', userSchema)
I also have
userSchema.virtual('finances', {
ref: 'finance',
localField: '_id',
foreignField: 'user'
})
如果我使用填充来获取用户以及用户所显示的财务状况,并且如果我使用填充来获取财务状况,那么我所获得的只是具有财务状况的帐户,而不是0中的所有帐户和财务状况
所以我想知道如何将用户和财务状况放在同一阵列中?