Relations in Document-oriented database?

前端 未结 6 1408
北恋
北恋 2021-02-18 23:14

I\'m interested in document-oriented databases, and I\'d like to play with MongoDB. So I started a fairly simple project (an issue tracker), but am having hard times thinking in

6条回答
  •  既然无缘
    2021-02-18 23:51

    I like MongoDB, but I have to say that I will use it a lot more soberly in my next project.

    Specifically, I have not had as much luck with the Embedded Document facility as people promise.

    Embedded Document seems to be useful for Composition (see UML Composition), but not for aggregation. Leaf nodes are great, anything in the middle of your object graph should not be an embedded document. It will make searching and validating your data more of a struggle than you'd want.

    One thing that is absolutely better in MongoDB is your many-to-X relationships. You can do a many-to-many with only two tables, and it's possible to represent a many-to-one relationship on either table. That is, you can either put 1 key in N rows, or N keys in 1 row, or both. Notably, queries to accomplish set operations (intersection, union, disjoint set, etc) are actually comprehensible by your coworkers. I have never been satisfied with these queries in SQL. I often have to settle for "two other people will understand this".

    If you've ever had your data get really big, you know that inserts and updates can be constrained by how much the indexes cost. You need fewer indexes in MongoDB; an index on A-B-C can be used to query for A, A & B, or A & B & C (but not B, C, B & C or A & C). Plus the ability to invert a relationship lets you move some indexes to secondary tables. My data hasn't gotten big enough to try, but I'm hoping that will help.

提交回复
热议问题