I'm new to MongoDB, so please bear with me.
I have 2 questions:
First, take the following:
// add a record
$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
Does MongoDB store "title" and "author" as text for every single entry of this object in this collection? Or does it create a schema and convert these to field numbers (or nothing at all and store purely the data)?
My second question is: when should "relations" be used? Let's say I have 100 resellers, who contain (object-wise) 1,000 clients each, and each client has 10 projects. That makes for one huge overall object to manipulate.
In the SQL world, this would all be related "objects". In the Document world, we try to store complete objects by embedding sub-objects.
However, this can be unwieldy. What is the best practice for this? Can someone point me to a guideline please.
Thanks.
title
andauthor
are stored as text in the DB. Depending on the language/driver/wrapper you are using, this can typically be re-mapped so that the field ist
in the database, buttitle
when accessed from your objects. From the standpoint of relationships, you'll typically find that you'll have to optimize for "something". There is no single "best way". – Geldens