我的数据库架构适合与 Mongo 一起使用吗?
太长了;博士 我的架构还好吗?
我今年的决心是学习一些新的东西,我选择学习一些关于非相关数据库的知识,即 Mongo。我目前正在开发一个简单的应用程序,它使用 mongo 作为数据库引擎。
我正在开发的应用程序是一个简单的问卷应用程序:管理员创建问题,(登录)用户回答它们。所以:用户有很多答案属于问题。 对于这样的应用程序最合适的架构是什么?我自己创建了下一个架构(伪),但我想知道您是否有任何解决此问题的提示/技巧。
users [
{
# some required fields to authenticate the user
email: [email protected],
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.
]
tl;dr
Is my schema okay?
My resolution for this year is to learn something new, and I've chosen to learn something about non-rel databases, i.e. Mongo. I'm currently working on a simple app which uses mongo as the database engine.
The application I'm working on is a simple questionnaire app: admin creates question, (logged in) user answers them. So: User has many Answer belongs to Question. What would be the most appropriate schema for such an app? I created the next schema myself (pseudo), but I'm wondering if you have any hints/tips solving this.
users [
{
# some required fields to authenticate the user
email: [email protected],
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.
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将答案移至问题集合中:
此外,使用动态字段(如答案 ID)将使您无法对它们建立索引。
I'd move answers inside questions collection:
Also using dynamic fields (like answer IDs) will make you impossible to index them.