【发布时间】:2021-07-13 12:53:31
【问题描述】:
假设我在“帖子”集合中有文档。我想将这些文档视为一个集合 - 例如,搜索它们或对所有文档一起运行 db.posts.find()。
但是,有明显不同的帖子类型,理想情况下应该有不同的架构。例如,“文本”帖子可能是:
post_type: "text",
author: String,
title: String,
body: String
“图片”帖子可能是:
post_type: "image",
uri: String,
thumbnail: String
是否有一种简洁的方法可以为同一集合中的不同类型文档定义多个模式?
谢谢!
【问题讨论】:
标签: database mongodb mongoose database-design mongoose-schema