Docs Menu
Docs Home
/
MongoDB ๋งค๋‰ด์–ผ
/ /

๋„ค์ดํ‹ฐ๋ธŒ ๋ฉ”์„œ๋“œ mongosh

์ด ์„น์…˜์— ๋‚˜์—ด๋œ ๋ฉ”์„œ๋“œ๋Š” mongosh ๋ ˆ๊ฑฐ์‹œ ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์—ˆ๋˜ ๋„ค์ดํ‹ฐ๋ธŒ ๋ฉ”์„œ๋“œ๋ฅผ ์œผ๋กœ ๋Œ€์ฒดํ•˜๋Š” mongo shell ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฉ”์„œ๋“œ๋Š” ์ •ํ™•ํžˆ ๋Œ€์ฒด๋˜์ง€ ์•Š์œผ๋ฉฐ ์ถœ๋ ฅ ํ˜•์‹๊ณผ ์ผ๋ถ€ ๊ธฐ๋Šฅ์ด ํ•ด๋‹น ๋ ˆ๊ฑฐ์‹œ ๋ฉ”์„œ๋“œ์™€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋Ÿฌํ•œ ๋ฉ”์„œ๋“œ ์™ธ์—๋„ mongocompat ์Šค๋‹ˆํŽซ mongo shell ๋ ˆ๊ฑฐ์‹œ API์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ 

๋‹ค์Œ ํ‘œ์—์„œ <path> ๋ฐ <filename> ์€ ๋ฌธ์ž์—ด์ด๋ฉฐ ๋”ฐ์˜ดํ‘œ๋กœ ๋ฌถ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

// process.chdir( <path> )
process.chdir( "./data/incoming" )
๋ ˆ๊ฑฐ์‹œ ๋ฉ”์„œ๋“œ ์ด๋ฆ„
๊ต์ฒด

cat()

์ง€์ •๋œ ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

fs.readFileSync( <filename>, 'utf8' )

๋ ˆ๊ฑฐ์‹œ useBinaryMode ์˜ต์…˜์€ ์ง€์›๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ useBinaryMode = false ์˜ต์…˜์„ ์—๋ฎฌ๋ ˆ์ด์…˜ํ•ฉ๋‹ˆ๋‹ค.

fs.readFileSync( <filename>, 'utf8' ).replace( /\r\n/g, '\n' )

cd()

ํ˜„์žฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ง€์ •๋œ ๊ฒฝ๋กœ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

process.chdir( <path> )

getHostName()

mongosh๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์‹œ์Šคํ…œ์˜ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

os.hostname()

getMemInfo()

shell์—์„œ ์‚ฌ์šฉํ•œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋ณด๊ณ ํ•˜๋Š” ๋ฌธ์„œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

process.memoryUsage()

hostname()

์…ธ์„ ์‹คํ–‰ํ•˜๋Š” ์ปดํ“จํ„ฐ์˜ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

os.hostname()

isInteractive()

mongosh๊ฐ€ ๋Œ€ํ™”ํ˜• ๋ชจ๋“œ์—์„œ ์‹คํ–‰ ์ค‘์ธ์ง€ ์Šคํฌ๋ฆฝํŠธ ๋ชจ๋“œ์—์„œ ์‹คํ–‰ ์ค‘์ธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ถ€์šธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

isInteractive()

listFiles()

๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” ๊ฐ ๊ฐ์ฒด์˜ ์ด๋ฆ„๊ณผ ์œ ํ˜•์„ ์ œ๊ณตํ•˜๋Š” ๋ฌธ์„œ ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

fs.readdirSync( <path>, { withFileTypes: true } )

load()

์…ธ์—์„œ JavaScript ํŒŒ์ผ์„ ๋กœ๋“œํ•˜๊ณ  ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

load() mongosh ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. require()์™€ load()์˜ ์ฐจ์ด์ ๋„ ์ฐธ์กฐํ•˜์„ธ์š”.

ls()

ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” ํŒŒ์ผ ๋ชฉ๋ก์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

fs.readdirSync( <path> )

md5sumFile()

์ง€์ •๋œ ํŒŒ์ผ์˜ md5 ํ•ด์‹œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

crypto.createHash( 'md5' ).update( fs.readFileSync( <filename> ) ).digest( 'hex' )

mkdir()

์ง€์ •๋œ ๊ฒฝ๋กœ์— ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

fs.mkdirSync( <path>, { recursive: true } )

pwd()

ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

process.cwd()

quit()

ํ˜„์žฌ ์…ธ ์„ธ์…˜์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

quit()

removeFile()

๋กœ์ปฌ ํŒŒ์ผ ์‹œ์Šคํ…œ์—์„œ ์ง€์ •๋œ ํŒŒ์ผ์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

fs.unlinkSync( <filename> )

sleep()

์ง€์ •๋œ ์‹œ๊ฐ„(๋ฐ€๋ฆฌ์ดˆ) ๋™์•ˆ ํœด๋ฉด ์ƒํƒœ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

sleep( <number> )

version()

mongosh ์ธ์Šคํ„ด์Šค์˜ ํ˜„์žฌ ๋ฒ„์ „์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

version()

_isWindows()

shell์ด Windows์—์„œ ์‹คํ–‰ ์ค‘์ธ ๊ฒฝ์šฐ true ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

process.platform === 'win32'

_rand()

0 ~ 1 ์‚ฌ์ด์˜ ๋‚œ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Math.random()

๋Œ์•„๊ฐ€๊ธฐ

Mongo์‰ฌ ๋ฐฉ๋ฒ•