【发布时间】:2021-08-10 12:23:15
【问题描述】:
我正在为我的在线书籍阅读设计一个关注功能,该功能大约有 10 万本书。所以我想知道哪个是使用 MongoDB 的更好方法。
- 将后面的所有书籍推入数组并存储为 1 个文档。当达到最大文档时,我们拆分为另一个文档
- 当用户关注一本书时,我们创建一个需求文档
请帮助我指出每种方式的优缺点或比上述两种方式更好的新方式来达到这种情况
const mongoose = require('mongoose');
const {comicConnection} = require('../db');
const Schema = mongoose.Schema;
const UserFollowsSchema = new Schema(
{
userId: { type: Schema.Types.ObjectId, ref: 'Users' },
follow: [{ type: Schema.Types.ObjectId, ref: 'Books' }],
},
{
timestamps: true,
}
);
module.exports = comicConnection.model(
'UserFollows',
UserFollowsSchema,
'UserFollows'
);
【问题讨论】:
标签: node.js database mongodb mongoose