我正在为 MERN 堆栈应用程序实现社交功能(关注/取消关注用户),并尝试提出一个良好的 MongoDB 解决方案,以避免潜在的大量无限关注者出现问题。具体来说,我希望避免:
从我研究的所有内容来看,似乎使用存储桶模式方法是最好的解决方案......我在这方面找到了两篇好文章: https ://www.mongodb.com/blog/post/paging-with-the-桶模式--part-1 https://www.mongodb.com/blog/post/paging-with-the-bucket-pattern--part-2
我开始像这样处理它......追随者模型:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const FollowerSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'user',
},
// creating an array of followers
followers: [
{
user: {
type: Schema.Types.ObjectId,
ref: 'user',
},
datefol: {
type: Date,
default: Date.now,
},
},
],
count: {
type: Number,
},
createdate: {
type: Date,
default: Date.now,
required: true,
},
});
module.exports …Run Code Online (Sandbox Code Playgroud)