アプリケーションでタイムラインのようなものを表示するためにアクティビティ モデルを作成したいのですが、マングース スキーマでコレクションを動的に参照する方法が正確にはわかりません。私はマングースを使用しています(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:
});
可能であれば、マングースで動的参照を使用してこれを解決するにはどうすればよいですか?また、どのように設定しますか?
ありがとうございました!