问题
I am currently writing a thesis and need to display the schema of my MongoDB in a diagram. I have found no resources about diagrams for document-based databases.
There are Entity Relationship Diagrams (ERD) for relational databases. What options do I have for MongoDB? I've noticed that a lot of blogs just display the raw JSON as their "diagram" but this isn't feasible in my thesis.
Here is a sample of one of my JSON structures:
//MultiChoiceQuestion
{
"title": "How are you?",
"valid_answers" : [
{
"_id" : ObjectID(xxxx),
"title": "Great",
"isCorrect": true,
},
{
"_id" : ObjectID(yyyy),
"title": "OK",
"isCorrect": false,
},
{
"_id" : ObjectID(zzzz),
"title": "Bad",
"isCorrect": false,
}
],
"user_responses" : [
{
"user": ObjectID(aaaa),
"answer": ObjectID(xxxx)
},
{
"user": ObjectID(bbbb),
"answer": ObjectID(xxxx)
},
{
"user": ObjectID(cccc),
"answer": ObjectID(yyyy)
}
]
}
//User
{
"_id": ObjectID(aaaa),
"name": "Person A"
}
//User
{
"_id": ObjectID(bbbb),
"name": "Person B"
}
//User
{
"_id": ObjectID(cccc),
"name": "Person C"
}
Could this be a possible diagram:

回答1:
We found class diagrams to actually be one of the best ways to represent a mongo schema design.
It can capture most of the items that a document will have such as arrays, embedded objects and even references.
General guidelines we use to relate onto concepts to uml
Embed = Composition aggregation
Reference = Association class
If you're unfamiliar with the uml terminology then this is a decent intro.
UML intro from IBM site
回答2:
There is a tool doing diagrams for MongoDb, is called DbSchema. It discovers the schema by scanning data from db. I would also suggest trying two features from them :
- virtual relations which allow exploring data from different collections in the same time. A kind of JOIN between different collections.
- HTML documentation, we use it in presentations as well - the comments are in mouse-over ( diarams are saved as vector images ).
来源:https://stackoverflow.com/questions/11323841/mongodb-how-to-represent-a-schema-diagram-in-a-thesis