I’m breaking my head over this:
The User on my WebApp can follow a Tag (Like a user can follow a subreddit), the followed Tag will be shown in the Homepage with a different color than the not followed one.
If a User follows a Tag he will get Push-Notifications when a new Blog Post is published tagged with the Tag.
So I have to query for all the tags a given user follows.
And I have to query for all the user which follow a given tag.
A user can follow max 20 Tags.
Since I have a Many to Many relation should i go with something like this (normalization)
const SubscribeToTagSchema = new Mongoose.Schema({
user: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
tag: {
type: Schema.Types.ObjectId,
ref: "Tag",
required: true,
},
});
or should I just save the data in both schema User and Tag?
const UserSchema = new Mongoose.Schema({
tag: {
type: Schema.Types.ObjectId,
ref: "Tag",
required: true,
},
});
const TagSchema = new Mongoose.Schema({
user: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
});