这是我的2种模式:
var activationTokenSchema = new Schema({
token: String,
});
var userSchema = new Schema({
name: String,
login: String,
email: String,
password: String,
balance: Number,
isActivated: Boolean,
activationToken: { type: Schema.Types.ObjectId, ref: 'ActivationToken' }
});
const User = mongoose.model('User', userSchema);
const ActivationToken = mongoose.model('ActivationToken', activationTokenSchema);
User
是父模型,具有子模型ActivationToken
。
仅具有token
字符串,如何查找用户文档?
还是重新设计ActivationTokenSchema
并在其中包含userId
更好,这样只有孩子会指向父母?