简体   繁体   English

mongodb中的对象元数据(模式)设计

[英]Object metadata (schema) design in mongodb

First of all excuse me since I don't know how it is called in computer since: 首先,对不起,因为我不知道在计算机中如何称呼它,因为:

For each of my document types in my mongo app I want to define a structure, with every field defined with its constraints, validation patterns and, generally, roles that can view modify and delete this document. 我想为mongo应用程序中的每种文档类型定义一个结构,每个字段都定义了其约束,验证模式以及通常可以查看的角色,这些角色可以查看修改和删除此文档。

For example: Book : 例如: Book

{
 name: "Book",
 viewRoles: ["Admin","User"],
 createRoles: ["Admin"],
 modifyRoles: ["Admin", "User"],
 fields: [
 {
    id:"title",
    name:"Book Title",
    validation: "",
    maxLength: 50,
    minLength: 3,
    required: true
   },
   {
    id:"authorEmail",
    name:"Email of the Author",
    validation: "email",
    maxLength: 50,
    minLength: 3,
    required: false
   }
 ]
}

Then if I have this "schema" for all of my documents, I can have one view for creating modifying and showing this "entities". 然后,如果我所有文档都具有这种“模式”,则可以使用一个视图来创建修改和显示此“实体”。

I also want to have the ability to create new document types, modify their fields through admin panel of my application. 我还希望能够创建新的文档类型,并通过应用程序的管理面板修改其字段。

When I google "mongo dynamic schema", "mongo document meta design" I get useless information. 当我用谷歌搜索“ mongo动态模式”,“ mongo文档元设计”时,我得到了无用的信息。

My question is how it is called -- when I want to have predefined schema of my documents and have the ability to modify it. 我的问题是如何称呼-当我想拥有预定义的文档架构并能够对其进行修改时。 Where I can get more information about how to design such systems? 在哪里可以获得有关如何设计此类系统的更多信息?

Since you tagged this as having a Meteor connection, I'll point you to Simple Schema: https://github.com/aldeed/meteor-simple-schema/ . 由于您将其标记为具有Meteor连接,因此,我将向您介绍简单架构: https : //github.com/aldeed/meteor-simple-schema/ I use it, along with the related collection2 package. 我将其与相关的collection2包一起使用。 I find it's a nice way to document and enforce schema design. 我发现这是记录和执行架构设计的好方法。 When used with the autoform package, it also provides a way to create validated forms directly from your schema. 当与autoform软件包一起使用时,它还提供了一种直接从您的架构中创建经过验证的表单的方法。

I think you are looking for how to model your data. 我认为您正在寻找如何对数据建模。 The below link might be helpful: 以下链接可能会有所帮助:

http://docs.mongodb.org/manual/data-modeling/ http://docs.mongodb.org/manual/data-modeling/

I also want to have the ability to create new document types, modify their fields through admin panel of my application. 我还希望能够创建新的文档类型,并通过应用程序的管理面板修改其字段。

For Administrative activities you may look into the options given in: 对于管理活动,您可以查看以下选项:

http://docs.mongodb.org/ecosystem/tools/administration-interfaces/ http://docs.mongodb.org/ecosystem/tools/administration-interfaces/

And once you are done, you might want to read this as a kick off: 完成后,您可能需要阅读以下内容作为开始:

https://blog.serverdensity.com/mongodb-schema-design-pitfalls/ https://blog.serverdensity.com/mongodb-schema-design-pitfalls/

In Mongo DB you don't create collections. 在Mongo DB中,您不创建集合。 You just start using them. 您只需开始使用它们。 So you can't define schemas before hand. 因此,您无法事先定义架构。 The collection is created on the first insert you make to the collection. 该集合是在您对该集合进行的第一个插入上创建的。 Just make sure to ensure Index on the collection before inserting documents into it: 只需在将文档插入其中之前确保在集合上确保索引:

db.collection.ensureIndex({keyField: 1})

So it all depends on maintaining the structure of the documents inserted to the collection rather than defining the collection. 因此,这全部取决于维护插入到集合中的文档的结构,而不是定义集合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM