Issues related to MongoDB database design

Source: Internet
Author: User
Tags mongodb query

Question one: Is it better to collection as little as possible, and to nest the relationships in a relational database into a document?
Question two: If this is the case, a SQL can handle complex queries, MongoDB may have to query multiple times. is MONGODB query faster than SQL database?
Question three: Where does MongoDB's advantage manifest itself? The mapreduce of hyper-scale data? Easy to expand?

Let me give you a chestnut :

Suppose this is the case in MySQL (meaning):

Authors (    int id,    char name,    int age,    char email) articles (    int id,    char title,    Char Content,    long viewcount,    int author_id)

  

So it might look like this in MongoDB:

There's only one authors collection.

    Author {        _id:new obectid ("Blublublu"),        Name: ' Portwatcher ', age        : ' + ',        email: ' [email protected] ',        articles: [{            title: ' You guess ',            content: ' I am content ',            viewcount:52345        }, ...]    }

  

The question is, if I want to find out all the author's articles separately and sort by the number of views, what do I do?

    • Then there is the second design approach, which is the embodiment of NoSQL = not-only SQL. There are authors and articles two collection
    Author {        _id:new obectid ("Blublublu"),        Name: ' Portwatcher ', age        : ' + ',        email: ' [email protected] '    }    Article {        _id:new ObjectID ("Lalalala"),        title: ' You guess ',        content: ' I am content ',        viewcount: 52345,        author_id: ' Blublublu '    }

  

Now the question is, what if I'm going to return the article and the author's name?
1. Do you want to check two times, even two times? If even once, some PAAs is not supported (for example, BAE, pro-Test does not support). Is this a loss of elegance?
2. If you save a copy of Author.name in article, when an author changes his name, the author will not be able to update the article, if the hard to update together, the cost is too large?
3. When will the dbref be used more appropriately? Here, how do you use it?

In this example, let's summarize what we need:

    • All authors ' articles can be aggregated back and sorted in some way
    • The article can be returned with the name of the author that matches it
    • The author can edit his own information
    • Both the article and the author can be inserted separately

May be more verbose, we understand.

If anyone could summarize some of the principles of MongoDB database design is better ~

Issues related to MongoDB database design

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.