MongoDB and Mongoose package - MrKwon/node.js GitHub Wiki
MongoDB๋
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ๋ฒ์ ์ฌ์ฉ
- ํน์์ด ๋๋ ทํ NoSQL(Not only SQL)
- ํน์ง
- ๋ฐ์ดํฐ ๊ท์น ์์ด ์์ ๋ก์ด ์
๋ ฅ๊ฐ๋ฅ
- ์ปฌ๋ ์
๊ฐ์ JOIN ๋ถ๊ฐ
- Transaction ๋ถ๊ฐ
- ํ์ฅ์ฑ / ๊ฐ์ฉ์ฑ์ด ๋์
- Collection(MySQL - Table), Document(MySQL - Row), Field(MySQL - Column)
- Collection์๋ MySQL๊ณผ ๋ค๋ฅด๊ฒ Column ์ ์๊ฐ ํ์์์
MongoDB์ CRUD
- Create
db.[collection_name].save({ data properties });
- Read
db.[collection_name].find({ /* ์กฐํ์ ์กฐ๊ฑด properties */ } [, { /*์กฐํํ ํ๋ properties - 1(๊ฐ์ ธ์ฌ ๊ฐ) / 0(์ ๊ฐ์ ธ์ฌ ๊ฐ)*/ } );
์กฐ๊ฑด์ ์ฌ์ฉ๋๋ ์ฐ์ฐ์ (
$gt
: greater than
$gte
: greater than and equal
$lt
: less than
$lte
: less than and equal
$ne
: not equal
$or
: or
$in
: element in array
- Update
db.[collection_name].update({ /* ์์ ํ document ์ง์ */}, { $set/* ์ด๋ค ํ๋๋ฅผ ์์ ํ ์ง ์ ํ๋ ์ฐ์ฐ์, ์์ผ๋ฉด ๊ฐ์ฒด๊ฐ ํต์ฒด๋ก ๋ฐ๋*/: { /* ์์ ํ properties */ } });
- Delete
db.[collection_name].remove({ /* ์์ ํ document ์ง์ */ });
Mongoose๋
- ODM(Object Document Mapping) - MongoDB๋ Relation์ ์ฌ์ฉํ์ง ์๊ธฐ ๋๋ฌธ์ [Sequelize์ ๋ค๋ฅด๋ค].(https://github.com/MrKwon/node.js/wiki/Sequelize-Module#sequelize๋), ์๋ฐ์คํฌ๋ฆฝํธ์ Document(MySQL์ Relation๊ฒฉ)์ ๋งคํํด์ฃผ๋ ๋๊ตฌ
- ์๋ฐ์คํฌ๋ฆฝํธ(MongoDB)์ ์๋ฐ์คํฌ๋ฆฝํธ(Mongoose)๋ฅผ ๋งคํํ๋ ์ด์ ๋ ๋๊ฐ๊ฐ ๋ณด์์ ๊ด๊ณ์ด๊ธฐ ๋๋ฌธ์ด๋ค.
- ๋ชฝ๊ตฌ์ค์๋ ์คํค๋ง๊ฐ ์๋ค. - ์คํค๋ง๋ ๋
ธ๋ ์๋ฒ๋จ์์ ๋ฐ์ดํฐ๋ฅผ ํ๋ฒ ํํฐ๋ง ํด์ค๋ค. => MongoDB์์ ์ค์ํ๋ ๊ฒ์ ๋ฐฉ์งํด์ค๋ค.
- ๋ชฝ๊ตฌ์ค์
populate()
๋ฉ์๋๋ก ๊ด๊ณ๊ฐ ์๋ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋ ๊ฒ์ ๋์์ค๋ค.