我正在制作一个与Reddit非常相似的论坛应用程序。我在这里使用猫鼬进行架构设计。我对自己拥有的模型有疑问-用户,帖子和评论。
SUM( (4-(DECODE(c.qty1,0,1,0) + DECODE(c.qty2,0,1,0) + DECODE(c.qty3,0,1,0) + DECODE(c.qty4,0,1,0)))) NON_ZERO_QTY
模式,但实际上需要吗?我当前拥有的所有模型:
Friend
const userSchema = new Schema(
{
username: { type: String, required: true },
email: { type: String, reuired: true },
password: { type: String, required: true },
country: { type: String, required: true },
friends: [{ type: Schema.Types.ObjectId, ref: "Friend" }], // is it needed?
posts: [{ type: Schema.Types.ObjectId, ref: "Post" }],
},
{ timestamps: true }
)
const postSchema = new Schema(
{
title: { type: String, required: true },
description: { type: String, required: true },
user: { type: Schema.Types.ObjectId, ref: "User" },
slug: { type: String, slug: "title" },
upvotes: { type: Number },
downvotes: { type: Number },
city: { type: String }, // post will have a tag by the city like NewYork, LA etc.
},
{ timestamps: true }
)
答案 0 :(得分:1)
对于第二个问题,您不需要friend
模式,因为friend
也是user
。