Question about MongoDB from SQL user

I am very interested in using MongoDB, this seems awesome. But I'm from a completely different school: relational databases.

So now I am wondering how this case will work with MongoDB:

Let's say I have a table filled with brands, and I have another table filled with products.

Each product will have a brand. It is very easy to understand, but I still do not understand how it works with MongoDB?

I mean, should I repeat the brand every time I add a product? Can I make some kind of relationship?

Thank you for enlightening me :)

+3
source share
2 answers
  • Insert Brands
  • Paste pasted products (with brands)
  • Request him

:

Brands:

db.things.save({'name': 'Ford'});
db.things.save({'name': 'Mitsubishi'});

:

db.things.save({'brand': 'Ford', 'name': 'Mustang'});
db.things.save({'brand': 'Ford', 'name': 'Falcon'});
db.things.save({'brand': 'Mitsubishi', 'name': 'Delica'});
db.things.save({'brand': 'Mitsubishi', 'name': 'L300'});

db.things.find();
db.things.find({'brand': 'Ford'});
db.things.find({'brand': 'Mitsubishi'});

// ( ..) , tutorial manual . :)

+2

- :

{'brand':'brand one', 'products':
                       [{'product name':'a fine product','price':'$50'},
                        {'product name':'yet another fine product','price':'$20'}]
},
{'brand':'brand two', 'products':
                       [{'product name':'brand two product','price':'$10'}]
}

"" ( ). mongodb, , .

, nosql .

+3

Source: https://habr.com/ru/post/1754491/


All Articles