在一个属性中拥有多个数据型是什么时候有意义的?
在MongoDB或其他NOSQL数据库中,您没有架构。例如,您可以将员工的“名称”保存为字符串,也可以将其保存为整数。您不能在SQL数据库中执行此操作。但是保存名称= 3或类似的东西确实没有意义。我的问题是什么时候有一个属性具有不同的数据类型是有意义的?你能给我一些例子吗?
In MongoDB or other NoSQL Databases you dont have a schema. For example you can save the "name" of an employee as an String but also as an integer. You cant do this in SQL Databases. But it doesnt really make sense to save a name = 3 or something like that. My question is when does it make sense to have different datatypes for one attribute? Can you give me some examples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这全都与灵活性有关。 NOSQL涵盖了许多用例,例如分析,物联网,付款,欺诈检测等。如果您仔细看,所有这些都是半结构化或非结构化数据。灵活的架构使事情变得更容易,从而更轻松。但是,当您将不同的数据类型用于字段时,您最终将获得多个条件逻辑。
例如,您需要分析所有大学,学校学生的详细信息与疫苗相关的分析。如果您看到一所学校的ID可能是数字,另一个学校可能是alpha -numeric,其他人可能具有 - 。
如果您需要遵循严格的模式,则需要在加载之前进行预处理。 ORELSE您可以使用很少的有条件转换的数据生活。
如果您看到另一个示例日期字段,则可以使用时间戳,日期对象,字符串。当您在此日期字段上查询时,需要应用转换。
NOSQL不仅与整个模式有关。您无需强制设置缺失字段的默认值。您可以拥有复杂的嵌套数据类型。使用NOSQL时,您可以快速开始您的业务需求,因为您不必担心桌子,人际关系。但是从长远来看,您的NOSQL模式将发展并获得成熟的状态。如果您只想进行临时分析,则可以从非结构化/半=结构化数据开始。
It is all about the flexibility. NoSql covers lots of use-cases such as analytics, IOTs, payments, fraud detection, etc. If you look carefully, all are either semi structured or unstructured data. Flexible schema makes things easier in terms of incremental development. But when you use different data types for a field, you will end up with multiple conditional logics.
For example, you need to analyse all the university, school students' details for the vaccination related analytics. If you see id of one school may be numeric, other may be alpha-numeric, other may have characters like -.
If you need to follow strict schema, you need to preprocess it before loading. OrElse you can live with the data with few conditional conversions.
If you see another example date fields, you either can have timestamps, Date objects, Strings. When you query on this date field, you need to apply conversions.
NoSQL is not only about types, about entire schema. You don't need to forcefully set default values for missing fields. You can have complex nested data types. You can quickly get started with your business need when using NoSql as you don't need to worry much about tables, relationships. But in the long-run, your nosql schema will evolve and get a matured state. If you just want to do ad hoc analysis, you can get started with your unstructured/semi=structured data.