Structuring mongo db vs mysql

I have only worked with php and mysql so am used to normalising my database and doing a lot of table joins etc. but I am moving over to node.js now and using mongoose with mongo DB and what I have gathered is that you shouldn't structure your db in the same way you would using php mysql. Apparently you should rather have a denormalised database. Could anyone give me an idea of where I could find a good example of this or possibly explain this in terms of an example? I have attached an image of a relational database setup I found on google and just wondered how the mongo db database would differ?
Black SulfurAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
this gives a good explanation:

The main difference would be that the orders table would have orders detail as a field rather than a separate table (probably as a nested document).

If you really want to learn they offer free courses:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
Apparently you should rather have a denormalised database.
hmm, nope. The problem are the concepts.

Normalization is defined in for relational database systems as how to implement tables to avoid redundancy and to enforce logical integrity. Sadly enough, they reuse the word, but change the meaning. Here "Normalization" means relationship between documents.

So, as MongoDB is NoSQL and document oriented, apply this to your ERD: You simply have 1..N product descriptions and 1.N orders in your database. When an order is placed, you simply store the entire order as a single document in your database. E.g. something like

    _id: <ObjectId1>,
    orderNo: 1232,
    invoiceAddress: { /* complete address */ },
    shippingAddress: { /* complete address */ },
    orders: [ { /* complete order position */ }, { /* complete order position */ } ],
    orderTotalAmonut: 0.0,
    orderTax: 0.0

Open in new window

nociSoftware EngineerCommented:
They both have their strong points.

Consider looking up an order position , you will need to search all Orders to find it in NoSql.
In SQL you could would have a different table with it's own indexes.

Can't find a  link any more.. Someone converted a Mysql -> MongoDB for a movie database.
No problem to order using films as a starting point and drill down to cast  etc.
Finding an actor and in what films they played was quite not that simple to build in anymore.
(more or less the same problem).  N:M relations can be a problem.
ste5anSenior DeveloperCommented:
You query Mongo by using "filter documents".
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.