我的DB模式可以与Mongo使用吗?
-
09-10-2019 - |
题
tl; dr我的模式还好吗?
我今年的解决方案是学习一些新知识,我选择学习有关非REL数据库的知识,即Mongo。我目前正在使用使用Mongo作为数据库引擎的简单应用程序。
我正在处理的应用程序是一个简单的问卷应用程序:管理员创建问题,(登录)用户回答了它们。因此:用户有很多答案属于问题。 这样的应用程序最合适的模式是什么? 我自己创建了下一个模式(伪),但是我想知道您是否有任何提示/提示解决此问题。
users [
{
# some required fields to authenticate the user
email: j.doe@example.com,
password: ...
etc.
# next fields are this users answers to a question
# the key is the question's id, it's value the answer
1: 'John',
2: 'Doe',
},
]
questions [
{ # no 1 (I know id's in mongo aren't numbered this way,
# this is just for the sake of readability.
question: What is your first name?,
type: open,
required: true,
},
{ # no 2
question: What is your last name?,
type: open,
required: false,
},
# and so on.
]
解决方案
我会在问题收集中移动答案:
{_id: 1,
question: "?",
type: "open",
required: true,
answered: [
{email: "j.doe@example.com", answer: "John"},
{email: "bob@example.com", answer: "Bob"},
]
}
同样,使用动态字段(如答案ID)将使您无法索引它们。
不隶属于 StackOverflow