Note that there are some explanatory texts on larger screens.

plurals
  1. POProduct/ Category management in mongoDB and MySQL
    primarykey
    data
    text
    <p>I am a newbie with mongoDB. I write a simple application to manage product. I use mongoDB. This is my database</p> <p><code>Category</code> Collection:</p> <pre><code>db.category.insert({id:1,name:"Motor",description:"Sell Motor"}) db.category.insert({id:2,name:"Car":description:"Sell Car"}) </code></pre> <p><code>Product</code> Collection:</p> <pre><code>db.product.insert({id:1,name:"Honda CBR",price:15000,id_category:1}) db.product.insert({id:2,name:"Kawasaki ",price:16000,id_category:1}) db.product.insert({id:3,name:"Ford", price:50000,id_category:2}) </code></pre> <p>I think to find <code>Product</code> with <code>Category</code> name is <code>Motor</code>, I have to write tree queries:</p> <pre><code>var result = db.category.find({name:"Motor"}) var cat = result.next().id db.product.find({id_category:cat}) </code></pre> <p>In MySQL I can do the same thing with two table:</p> <pre><code>CREATE TABLE `product_manage`.`category`( `id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(2000), `description` VARCHAR(2000), PRIMARY KEY (`id`) ); CREATE TABLE `product_manage`.`product`( `id` INT NOT NULL, `name` VARCHAR(2000), `price` INT, `id_category` INT, PRIMARY KEY (`id`) ); </code></pre> <p>So I don't know what is the advantage of MongoDB over MySQL in this example. I want to ask some more:</p> <p>In mysql:</p> <p>case a:</p> <pre><code>select id into @id_cat where name="Motor" select * from product where id_category = @id_cat </code></pre> <p>case b:</p> <pre><code>select p.id,p.name,p.price from product p,category where p.id_category = category.id and category.name = "Motor" </code></pre> <p>Which case is good for performance?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload