MongoDB is a non-relational database. no joins, no rows, no columns. It's Document based.
MySQL is a relation database.
For example: We have some servers. Each server has a name, ip, admins, and OS. But some servers have extra data 'master'.
If is_slave == true: print name of the master server.
In MongoDB (without index; it's not relevant here):
{
"_id": ObjectId("4da5609a7650bf3f57000000"),
"name": "Testarossa",
"ip": "0.0.0.0",
"admins": [
{ "username": "yitsushi", "has_sudo": true },
{ "username": "lokko", "has_sudo": false }
],
"os_name": "Gentoo",
"is_slave": false
},
{
"_id": ObjectId("4decc3d1f2d26f6716000001"),
"name": "Amanuat",
"ip": "0.0.0.1",
"admins": [
{ "username": "yitsushi", "has_sudo": false },
{ "username": "parandokht", "has_sudo": true }
],
"os_name": "Ubuntu 10.10",
"is_slave": true,
"master": {
"name": "Testarossa",
"server": {
"$ref": "servers",
"$id": ObjectId("4da5609a7650bf3f57000000");
}
}
}
You can see the master field is not required, so you don't need to define it in each document instead of null
/0
values. And you can define an Array (admins) instead of related tables. In master field: we define an object with two properties: name (for print name of the server) and a reference (we can create a link with doc['master']['server']['$id']
or we can fetch with an other query the full document of the master server).
In MySQL we need a servers, an admins and a server_admins table (least) and some unnecessary fields whose value is null
.
MongoDB and MySQL is not same category. MongoDB is a non-relational, MySQL is a relational database. Completely different logic and attitude need to MongoDB or MySQL.
A perfect compare grid: MongoDB, CouchDB, MySQL Compare Grid at www.mongodb.org