我想创建一个活动模型,以便在我的应用程序中显示时间线类型的东西,但我不知道如何在猫鼬模式中动态引用集合。我使用猫鼬(3.6.20)
到目前为止,演员始终是用户,但 _object 可以是用户或帖子。
这就是我所拥有的:
userSchema = new Schema({
_id: ObjectId;
name: String
});
postSchema = new Schema({
_id: ObjectId;
author_id: String, ref: User
});
我想做的是:
activitySchema = new Schema({
_object: { String: Id of the thing, ref:'can be user or post'} // Object that the verb occurred on... can be a post or a user
actor: { type: String, ref: 'User' },
action: { type: String, default: ""}, //ex: has replied to:, or started following:
});
如果可能的话,我如何使用动态引用和猫鼬来解决这个问题,我将如何填充它?
谢谢!