MongoDB ๊ธฐ๋ณธ๋ช…๋ น์–ด

 

- ํ˜„์žฌ ์‚ฌ์šฉ์ค‘์ธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ™•์ธ

> db

- ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ชฉ๋ก ์กฐํšŒ

> show dbs

admin 0.000GB

config 0.000GB

local 0.000GB

 

- ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ณ€๊ฒฝ

(์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ƒˆ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ๋„ ๋ณ€๊ฒฝ๊ฐ€๋Šฅ, ์‹ค์ œ ์ƒ์„ฑ์€ ์ปฌ๋ ‰์…˜์ด ์ถ”๊ฐ€๋  ๋•Œ ๋˜๋Š” ๋“ฏ)

> use blogapp

switched to db blogapp

> show dbs

admin 0.000GB

config 0.000GB

local 0.000GB

 

- ํ˜„์žฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ปฌ๋ ‰์…˜ ๋ชฉ๋ก ์กฐํšŒ

> show collections

diary_life

 

- ์ปฌ๋ ‰์…˜ ๋ฐ ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€ (๋ฐ์ดํ„ฐ๋Š” json format์œผ๋กœ ๋„ฃ๋Š”๋‹ค)

db.<collection>.insertOne(<๋ฐ์ดํ„ฐ>);

> db.diary_life.insertOne({title: "ํ…Œ์ŠคํŠธ", content:"ํ…Œ์ŠคํŠธ ๊ฒŒ์‹œ๊ธ€์ž…๋‹ˆ๋‹ค"});

{ "acknowledged" : true, "insertedId" : ObjectId("5fb9a86c88b63c276fc5d50b") }

 

- ์ปฌ๋ ‰์…˜์˜ ๋ชจ๋“  ๋ฐ์ดํ„ฐ ์กฐํšŒ (find๋ฉ”์„œ๋“œ์— empty doc์„ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ „๋‹ฌ)

> db.diary_life.find({});

{ "_id" : ObjectId("5fb9a86c88b63c276fc5d50b"), "title" : "ํ…Œ์ŠคํŠธ", "content" : "ํ…Œ์ŠคํŠธ ๊ฒŒ์‹œ๊ธ€์ž…๋‹ˆ๋‹ค" }

 

- ํŠน์ • ๋ฐ์ดํ„ฐ ์—…๋ฐ์ดํŠธ

> db.diary_life.update({"title":"ํ…Œ์ŠคํŠธ"}, {title: "ํ…Œ์ŠคํŠธ", content:"์—…๋ฐ์ดํŠธ์™„๋ฃŒ"});

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.diary_life.find({});

{ "_id" : ObjectId("5fb9a86c88b63c276fc5d50b"), "title" : "ํ…Œ์ŠคํŠธ", "content" : "์—…๋ฐ์ดํŠธ์™„๋ฃŒ" }

 

- ์ปฌ๋ ‰์…˜์˜ doc ๊ฐœ์ˆ˜ ์กฐํšŒ

> db.diary_life.count();

1

 

- ํŠน์ • ๋ฐ์ดํ„ฐ ์‚ญ์ œ

> db.diary_life.deleteOne({"title":"ํ…Œ์ŠคํŠธ"});

{ "acknowledged" : true, "deletedCount" : 1 }

> db.diary_life.count(); 0

> db.diary_life.find({});

>

 

 

(์ฐธ๊ณ : https://docs.mongodb.com/manual/reference/method/ )