【发布时间】:2021-11-25 21:52:10
【问题描述】:
我想为类似于 instagram 的社交媒体应用程序设计 followers 和 followee(following) 模块。
我已经实现了以下相同的方法
用户架构
module.exports = mongoose.model('users', new Schema({
name: { type: String, default: null },
gender: { type: String, default: null, enum: ['male', 'female', 'others', null] },
email: { type: String, unique: true, sparse: true },
isBlocked: { type: Boolean, default: false },
isDeleted: { type: Boolean, default: false },
profileImage: { type: String, default: null },
isVerified: { type: Boolean, default: false },
}, {
versionKey: false,
timestamps: true
}));
追随者架构
module.exports = mongoose.model('followers', new Schema({
followeeId: { type: ObjectId, required: true },
followerId: { type: ObjectId, required: true }
}, {
versionKey: false,
timestamps: true
}));
当使用这种方法时,如果一个用户有 100 万关注者,那么 将为该用户创建 100 万条记录,如果用户关注了所有关注者,那么计数将是 200 万
所以平均而言:
user#1 has 1 million followers/followees = 1 million records // total records: 1 Million
user#2 has 1 million followers/followees = 1 million records // total records: 2 Million
.
.
user#1000 has 1 million followers/followees = 1 million records // total records: 1 Billion
.
.
user#1,000,000 has 1 million followers/followees = 1 million records // total records: 1 Trillion
如果我使用这种方法,将会有超过数万亿条记录在一个集合中
那么生成这样的记录可以吗?
或者请建议是否有任何不同的方法来设计这个架构
【问题讨论】:
标签: mongodb database-design database-schema