convertToCapped (์๋ฌธ)
์ ์
convertToCapped
๊ฒฝ๊ณ
์ค๋ ์ปฌ๋ ์ ์์๋ ์ด ๋ช ๋ น์ ์คํํ์ง ์์
MongoDB ๋ ์ค๋ฉ๋ ์ปฌ๋ ์ ์์
convertToCapped
๋ช ๋ น์ ์ง์ ํ์ง ์์ต๋๋ค .convertToCapped
๋ช ๋ น์ ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ด ์๋ ๊ธฐ์กด ์ปฌ๋ ์ ์ ๋์ผํ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ด์ ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ผ๋ก ๋ณํํฉ๋๋ค.
ํธํ์ฑ
์ด ๋ช ๋ น์ ๋ค์ ํ๊ฒฝ์์ ํธ์คํ ๋๋ ๋ฐฐํฌ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
MongoDB Atlas: ํด๋ผ์ฐ๋์์์ MongoDB ๋ฐฐํฌ๋ฅผ ์ํ ์์ ๊ด๋ฆฌํ ์๋น์ค
์ค์
์ด ๋ช ๋ น์ ์๋ฒ๋ฆฌ์ค ์ธ์คํด์ค์์๋ ์ง์๋์ง ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ง์๋์ง ์๋ ๋ช ๋ น์ ์ฐธ์กฐํ์ธ์.
MongoDB Enterprise: MongoDB์ ๊ตฌ๋ ๊ธฐ๋ฐ ์์ฒด ๊ด๋ฆฌ ๋ฒ์
MongoDB Community: MongoDB์ ์์ค ์ฌ์ฉ ๊ฐ๋ฅ ๋ฌด๋ฃ ์์ฒด ๊ด๋ฆฌ ๋ฒ์
๊ตฌ๋ฌธ
๋ช ๋ น์ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ๋ฌธ์ ๊ฐ์ง๋๋ค:
db.runCommand( { convertToCapped: <collection>, size: <capped size>, writeConcern: <document>, comment: <any> } )
๋ช ๋ น ํ๋
์ด ๋ช ๋ น์ ๋ค์ ํ๋๋ฅผ ์ฌ์ฉํฉ๋๋ค.
ํ๋ | ์ค๋ช
|
---|---|
convertToCapped (์๋ฌธ) | ๋ณํํ ๊ธฐ์กด ์ปฌ๋ ์ ์ ์ด๋ฆ์ ๋๋ค. |
size | ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ ์ต๋ ํฌ๊ธฐ(๋จ์: ๋ฐ์ดํธ)์ ๋๋ค. |
์ฐ๊ธฐ ๊ณ ๋ ค | ์ ํ ์ฌํญ. ๋ช
๋ น์ ์ฐ๊ธฐ ๊ณ ๋ ค |
| ์ ํ ์ฌํญ. ์ด ๋ช ๋ น์ ์ฒจ๋ถํ ์ฌ์ฉ์ ์ ๊ณต ์ฝ๋ฉํธ์ ๋๋ค. ์ค์ ๋๋ฉด ์ด ์ค๋ช ์ ๋ค์ ์์น์์ ์ด ๋ช ๋ น์ ๋ ์ฝ๋์ ํจ๊ป ํ์๋ฉ๋๋ค.
๋๊ธ์ ์ ํจํ ๋ชจ๋ BSON types (๋ฌธ์์ด, ์ ์, ๊ฐ์ฒด, ๋ฐฐ์ด ๋ฑ)์ด ๋ ์ ์์ต๋๋ค. |
convertToCapped
๋ ๊ธฐ์กด ์ปฌ๋ ์
(<collection>
)์ ๊ฐ์ ธ์์ size
์ธ์(<capped size>
)๋ก ์ง์ ๋ ์ต๋ ํฌ๊ธฐ(๋ฐ์ดํธ)๋ฅผ ๊ฐ์ง ๊ณ ์ ์ฌ์ด์ฆ ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์
์ผ๋ก ๋ณํํฉ๋๋ค.
๋ณํ ํ๋ก์ธ์ค ์ค์ convertToCapped
๋ช
๋ น์ ๋ค์๊ณผ ๊ฐ์ ๋์์ ๋ํ๋
๋๋ค.
MongoDB๋ ์๋ ์ปฌ๋ ์ ์ ๋ฌธ์๋ฅผ ์์ฐ์ค๋ฌ์ด ์์ ๋ก ํ์ํ๊ณ ๋ฌธ์๋ฅผ ์ ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ ๋ก๋ํฉ๋๋ค.
๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ ์ง์ ๋
capped size
๊ฐ ์๋ณธ ๋น๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ ํฌ๊ธฐ๋ณด๋ค ์์ ๊ฒฝ์ฐ, MongoDB๋ ์ฝ์ ์์ ๋๋ ์ ์ ์ ์ถ ์์์ ๋ฐ๋ผ ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ ๋ฌธ์๋ฅผ ๋ฎ์ด์๋๋ค.๋ด๋ถ์ ์ผ๋ก, MongoDB๋ collection์ ๋ณํํ๊ธฐ ์ํด ๋ค์ ์ ์ฐจ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
cloneCollectionAsCapped
๋ช ๋ น์ ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ ๋ง๋ค๊ณ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.MongoDB๋ ์๋ณธ collection์ ์ญ์ ํฉ๋๋ค.
renameCollection
๋ ์ ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์ ์ ์ด๋ฆ์ ์๋ ์ปฌ๋ ์ ์ ์ด๋ฆ์ผ๋ก ๋ฐ๊ฟ๋๋ค.
์ด๋ ์์ ๊ธฐ๊ฐ ๋์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ฐฐํ ๋ฝ์ ๋ณด์ ํฉ๋๋ค. ๋์ผํ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ธ์ ์ ์ฉํ ๋ค๋ฅธ ์์ ์ ํด๋น ์์ ์ด ์๋ฃ๋ ๋๊น์ง ์ฐจ๋จ๋ฉ๋๋ค. ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ธ์ ์ ์ฉํ๋ ์์ ์ ๊ดํ ๋ด์ฉ์ ์ผ๋ฐ์ ์ธ ํด๋ผ์ด์ธํธ ์์ ์์ ์ด๋ค ์ ๊ธ์ ์ฌ์ฉํ๋์?๋ฅผ ํ์ธํ์ธ์.
๊ฒฝ๊ณ
convertToCapped
๋ _id
ํ๋์ ์๋ ์ธ๋ฑ์ค๋ฅผ ์ ์ธํ ์๋ ์ปฌ๋ ์
์ ์ธ๋ฑ์ค๋ฅผ ์ ์ปฌ๋ ์
์ ๋ค์ ๋ง๋ค์ง ์์ต๋๋ค. ์ด ์ปฌ๋ ์
์ ์ธ๋ฑ์ค๊ฐ ํ์ํ ๊ฒฝ์ฐ ๋ณํ์ด ์๋ฃ๋ ํ์ ์ด๋ฌํ ์ธ๋ฑ์ค๋ฅผ ๋ง๋ค์ด์ผ ํฉ๋๋ค.
์์
collection ๋ณํ
๋ค์ ์์ ์์๋ db.collection.insertOne()
๋ฅผ ์ฌ์ฉํ์ฌ events
collection์ ๋ง๋ค๊ณ db.collection.stats()
๋ฅผ ์ฌ์ฉํ์ฌ collection์ ๋ํ ์ ๋ณด๋ฅผ ์ป์ต๋๋ค.
db.events.insertOne( { click: 'button-1', time: new Date() } ) db.events.stats()
MongoDB๋ ๋ค์์ ๋ฐํํฉ๋๋ค:
{ "ns" : "test.events", ... "capped" : false, ... }
events
collection์ ๊ณ ์ ์ฌ์ด์ฆ ์ปฌ๋ ์
์ผ๋ก ๋ณํํ๊ณ ์
๋ฐ์ดํธ๋ collection ์ ๋ณด๋ฅผ ๋ณด๋ ค๋ฉด ๋ค์ ๋ช
๋ น์ ์คํํฉ๋๋ค.
db.runCommand( { convertToCapped: 'events', size: 8192 } ) db.events.stats()
MongoDB๋ ๋ค์์ ๋ฐํํฉ๋๋ค:
{ "ns" : "test.events", ... "capped" : true, "max" : NumberLong("9223372036854775807"), "maxSize" : 8192, ... }
convertToCapped
๋ _id
ํ๋์ ์๋ ์ธ๋ฑ์ค๋ฅผ ์ ์ธํ ์๋ ์ปฌ๋ ์
์ ์ธ๋ฑ์ค๋ฅผ ์ ์ปฌ๋ ์
์ ๋ค์ ๋ง๋ค์ง ์์ต๋๋ค. ์ด ์ปฌ๋ ์
์ ์ธ๋ฑ์ค๊ฐ ํ์ํ ๊ฒฝ์ฐ ๋ณํ์ด ์๋ฃ๋ ํ์ ์ด๋ฌํ ์ธ๋ฑ์ค๋ฅผ ๋ง๋ค์ด์ผ ํฉ๋๋ค.
๋ค์๋ ์ฐธ์กฐํ์ธ์.