I have this credit schema
const CreditSchema = new Schema({
userId: Schema.Types.ObjectId,
credit: {
type: Number,
default: 0
},
log: [String]
})
I hope it can be retrieve in below call
exports.getUser = async function(req, res) {
const user = await User.findOne({_id: req.query.id})
.populate('credit')
.exec()
res.json(user)
}
But what I get is userSchema's data, I don't see the data from credit schema. This is how my userSchema look like
const UserSchema = new Schema({
name: {
type: String
},
credit: {
type: Schema.Types.ObjectId,
ref: 'Credit'
}
})
I really scratch my head, I have the data in my db and the _id
of userSchema is the same with userId
of creditSchema.