Docs Menu

C ๋“œ๋ผ์ด๋ฒ„ ์‹œ์ž‘ํ•˜๊ธฐ

MongoDB C ๋“œ๋ผ์ด๋ฒ„ ๋Š” MongoDB ์— ์—ฐ๊ฒฐํ•˜๊ณ  ๋ฐฐํฌ์„œ๋ฒ„ ์— ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ์™€ ์ƒํ˜ธ ์ž‘์šฉ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” C ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์ด ๊ฐ€์ด๋“œ C ์šด์ „์ž ์‚ฌ์šฉํ•˜์—ฌ MongoDB Atlas ์—์„œ ํ˜ธ์ŠคํŒ…๋˜๋Š” MongoDB cluster ์— ์—ฐ๊ฒฐํ•˜๊ณ  ํด๋Ÿฌ์Šคํ„ฐ ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฟผ๋ฆฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

ํŒ

MongoDB Atlas๋Š” ๊ด€๋ฆฌํ˜• ํด๋ผ์šฐ๋“œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„œ๋น„์Šค๋กœ, MongoDB deployment๋ฅผ ํ˜ธ์ŠคํŒ…ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ฐ€์ด๋“œ์˜ ๋‹จ๊ณ„์— ๋”ฐ๋ผ ์ž์ฒด ๋ฌด๋ฃŒ(์‹ ์šฉ์นด๋“œ ํ•„์š” ์—†์Œ) MongoDB Atlas ๋ฐฐํฌ์„œ๋ฒ„๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๊ฐ€์ด๋“œ ์— ๋”ฐ๋ผ ์ƒ˜ํ”Œ C ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ MongoDB Atlas ๋ฐฐํฌ์„œ๋ฒ„ ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์šด์ „์ž ๋˜๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด ์‚ฌ์šฉํ•˜์—ฌ MongoDB ์— ์—ฐ๊ฒฐํ•˜๋ ค๋Š” ๊ฒฝ์šฐ ๊ณต์‹ ๋“œ๋ผ์ด๋ฒ„ ๋ชฉ๋ก์„ ์ฐธ์กฐํ•˜์„ธ์š”.

C ์šด์ „์ž ๋‘ ๊ฐœ์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ libbson ๋ฐ libmongoc๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค. ์ด ๊ฐ€์ด๋“œ ์—์„œ๋Š” libbson์™€ ํ•จ๊ป˜ ๋ฒˆ๋“ค๋กœ ์ œ๊ณต๋˜๋Š” libmongoc๋ฅผ ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ•™์Šต ๋ด…๋‹ˆ๋‹ค.

ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์†Œ์Šค์—์„œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•˜์—ฌ C ์šด์ „์ž ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ค์น˜ํ•  ๋•Œ Linux ๋ฐฐํฌํŒ์€ ์„œ๋กœ ๋‹ค๋ฅธ ๋ฒ„์ „์˜ ์šด์ „์ž ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์šด์ „์ž ์„ค์น˜ํ•˜๊ธฐ ์ „์— ๋ฐฐํฌ์— ํฌํ•จ๋œ ๋ฒ„์ „์„ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

RHEL( RedHat Enterprise Linux ) ๋ฐฐํฌํŒ์˜ ๊ฒฝ์šฐ ์…ธ ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜์—ฌ ๋ฒ„์ „์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sudo dnf info mongo-c-driver-devel

Debian ๊ธฐ๋ฐ˜ ๋ฐฐํฌ์—์„œ๋Š” ์…ธ ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜์—ฌ ๋ฒ„์ „์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

apt-cache policy libmongoc-dev

์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์šด์ „์ž ๋ฒ„์ „์ด ์›ํ•˜๋Š” ๋ฒ„์ „์ด ์•„๋‹Œ ๊ฒฝ์šฐ ์†Œ์Šค์—์„œ ์šด์ „์ž ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์†Œ์Šค์—์„œ ์šด์ „์ž ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ•™์Šต ์†Œ์Šค์—์„œ C ๋“œ๋ผ์ด๋ฒ„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋นŒ๋“œํ•˜๊ธฐ ๊ฐ€์ด๋“œ ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์šด์ „์ž ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ•™์Šต ์šด์˜ ์ฒด์ œ์— ํ•ด๋‹นํ•˜๋Š” ํƒญ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

RHEL( RedHat Enterprise Linux ) ๋ฐฐํฌํŒ, ๋ฒ„์ „ 7 ์ด์ƒ ๋˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ RHEL ๊ธฐ๋ฐ˜ ๋ฐฐํฌํŒ์— ์šด์ „์ž ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Fedora๋ฅผ ์ œ์™ธํ•œ RHEL ๋ฐฐํฌ์— ์šด์ „์ž ์„ค์น˜ํ•˜๊ธฐ ์ „์— ๋จผ์ € EPEL(Enterprise Linux ์šฉ ์ถ”๊ฐ€ ํŒจํ‚ค์ง€) ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ํ™œ์„ฑํ™” ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ์‹œ ์™€ ๊ฐ™์ด epel-release ํŒจํ‚ค์ง€ ์„ค์น˜ํ•˜์—ฌ EPEL ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ํ™œ์„ฑํ™” ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

yum install epel-release

๊ทธ๋Ÿฐ ๋‹ค์Œ yum๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ C ์šด์ „์ž ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ ค๋ฉด ์…ธ ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ .

yum install mongo-c-driver-devel

์ฐธ๊ณ 

๊ฐœ๋ฐœ์ž ํŒจํ‚ค์ง€

์•ž์˜ ์ฝ”๋“œ ์˜ˆ์‹œ C ์šด์ „์ž ์‚ฌ์šฉํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋นŒ๋“œ ๋ฐ ํ•„์š”ํ•œ ๊ฐœ๋ฐœ์ž ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ํŒŒ์ผ ์—†์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋งŒ ์„ค์น˜ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ .

yum install mongo-c-driver

๋ฒ„์ „ 8 ์ด์ƒ์ธ RHEL ๋ฐฐํฌ์— ์„ค์น˜ํ•˜๋Š” ๊ฒฝ์šฐ yum ๋Œ€์‹  dnf ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•ž์˜ ์ฝ”๋“œ ์˜ˆ์ œ๋ฅผ ์‹คํ–‰ ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

Fedora ๋˜๋Š” ๋ฒ„์ „ ์ด์ƒ์˜ ์—”ํ„ฐํ”„๋ผ์ด์ฆˆ Linux ๋ฐฐํฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์•ž์˜ 8 ์˜ˆ์‹œ ์— ํ‘œ์‹œ๋œ ๊ฒƒ๊ณผ ๋™์ผํ•œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜๊ณ  yum ๋ฅผ ๋กœ ๋ฐ”๊ฟ” ์šด์ „์ž ์„ค์น˜ํ•  ์ˆ˜ dnf ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ์˜ˆ์‹œ Fedora ๋ฐฐํฌ์— C ์šด์ „์ž ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

dnf install mongo-c-driver-devel

Ubuntu ๋ฐ Ubuntu ํŒŒ์ƒ ์ œํ’ˆ์„ ํฌํ•จํ•œ Debian ๊ธฐ๋ฐ˜ Linux ๋ฐฐํฌ์—์„œ ์šด์ „์ž ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๊ณ ๊ธ‰ ํŒจํ‚ค์ง• ๋„๊ตฌ(APT)๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์…ธ ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜์—ฌ APT๋กœ ์šด์ „์ž ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

apt install libmongoc-dev

์•ž์˜ ์ฝ”๋“œ ์˜ˆ์‹œ C ์šด์ „์ž ์‚ฌ์šฉํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋นŒ๋“œ ๋ฐ ํ•„์š”ํ•œ ๊ฐœ๋ฐœ์ž ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ํŒŒ์ผ ์—†์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋งŒ ์„ค์น˜ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ .

apt install libmongoc-1.0-0

Windows ํ™˜๊ฒฝ์˜ ๊ฒฝ์šฐ ๋กœ์ปฌ ๋„๊ตฌ ์ฒด์ธ๊ณผ์˜ ์ตœ๋Œ€ ํ˜ธํ™˜์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•ด ์†Œ์Šค์—์„œ C ์šด์ „์ž ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋นŒ๋“œํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. vcpkg์™€๊ฐ™์€ ์†Œ์Šค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์†Œ์Šค์—์„œ ๋นŒ๋“œ๋ฅผ ์ž๋™ํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํŒ

vcpkg๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ•™์Šต Microsoft ์„ค๋ช…์„œ์—์„œ vcpkg ์‹œ์ž‘ํ•˜๊ธฐ ๊ฐ€์ด๋“œ ์ฐธ์กฐํ•˜์„ธ์š”.

vcpkg ๋งค๋‹ˆํŽ˜์ŠคํŠธ ๋ชจ๋“œ ์—์„œ ๋‹ค์Œ ์˜ˆ์‹œ ์™€ ๊ฐ™์ด ์šด์ „์ž ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ”„๋กœ์ ํŠธ์˜ vcpkg.json ๋งค๋‹ˆํŽ˜์ŠคํŠธ ํŒŒ์ผ ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

{
// ...
"dependencies": [
// ...
"mongo-c-driver"
]
}

vcpkg ํ†ตํ•ฉ์„ ์‚ฌ์šฉํ•˜์—ฌ CMake ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ vcpkg.json ๋งค๋‹ˆํŽ˜์ŠคํŠธ ํŒŒ์ผ ์žˆ๋Š” ๊ฒฝ์šฐ vcpkg๋Š” ๊ตฌ์„ฑ์„ ์ง„ํ–‰ํ•˜๊ธฐ ์ „์— ํ”„๋กœ์ ํŠธ์˜ ์ข…์†์„ฑ์„ ์ž๋™์œผ๋กœ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

vcpkg ํด๋ž˜์‹ ๋ชจ๋“œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์…ธ ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜์—ฌ ์šด์ „์ž ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

vcpkg install mongo-c-driver

์šด์ „์ž ์„ค์น˜ํ•˜๋ฉด ํ‘œ์ค€ CMake ๊ตฌ์„ฑ ํŒŒ์ผ ๊ณผ ์ƒ์„ฑ๋œ IMPORTED ๋Œ€์ƒ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ์‹œ ์™€ ๊ฐ™์ด CMakeLists.txt ํŒŒ์ผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

find_package(mongoc-1.0 CONFIG REQUIRED)
target_link_libraries(my-application
PRIVATE $<IF:$<TARGET_EXISTS:mongo::mongoc_shared>,mongo::mongoc_shared,mongo::mongoc_static>)

์ฐธ๊ณ 

์•ž์˜ ์˜ˆ์‹œ ์—์„œ {0}lt;IF:{0}lt;TARGET_EXISTS...>:...> ์ƒ์„ฑ๊ธฐ ํ‘œํ˜„์‹ ์‚ฌ์šฉํ•˜์—ฌ find_package() ๋ช…๋ น์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ˜•์‹์— ๋”ฐ๋ผ libmongoc ์˜ ๋งํฌ ์œ ํ˜•์„ ์ „ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋Š” ๋™์  ๋ฐlibmongoc ์ •์  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์œ ํ˜•์„ ๋ชจ๋‘ ์‚ฌ์šฉํ•˜์—ฌ ๋นŒ๋“œ๋ฅผ ์ง€์›ํ•˜์ง€๋งŒ vcpkg๋Š” ํ•œ ๋ฒˆ์— ํ•˜๋‚˜์˜ ์œ ํ˜•๋งŒ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

vcpkg ํ†ตํ•ฉ์„ ์‚ฌ์šฉํ•˜์—ฌ CMake ํ”„๋กœ์ ํŠธ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด ์…ธ ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜์—ฌ ๊ตฌ์„ฑ ๋ช…๋ น์—์„œ CMake ๋„๊ตฌ ์ฒด์ธ ํŒŒ์ผ ์„ค์ •ํ•˜๋‹ค .

cmake -S . -B _build -D
CMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake

MacOS์—์„œ Homebrew ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ C ์šด์ „์ž ๋‹ค์šด๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ ค๋ฉด ์…ธ ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ .

brew install mongo-c-driver

์ด ๋‹จ๊ณ„๋ฅผ ์™„๋ฃŒํ•˜๋ฉด ์ปดํ“จํ„ฐ์— C ์šด์ „์ž ์„ค์น˜๋ฉ๋‹ˆ๋‹ค.

MongoDB Atlas์— ํ”„๋ฆฌ ํ‹ฐ์–ด MongoDB ๋ฐฐํฌ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. MongoDB Atlas๋Š” ํด๋ผ์šฐ๋“œ์—์„œ MongoDB database๋ฅผ ํ˜ธ์ŠคํŒ…ํ•˜๊ณ  ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

1

Atlas ์‹œ์ž‘ํ•˜๊ธฐ ๊ฐ€์ด๋“œ๋ฅผ ์™„๋ฃŒํ•˜์—ฌ ์ƒˆ Atlas ๊ณ„์ •์„ ์„ค์ •ํ•˜๊ณ  ์ƒˆ๋กœ์šด ํ”„๋ฆฌ ๊ณ„์ธต MongoDB ๋ฐฐํฌ์„œ๋ฒ„์— ์ƒ˜ํ”Œ ๋ฐ์ดํ„ฐ๋ฅผ ๋กœ๋“œํ•˜์„ธ์š”.

2

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•œ ํ›„ ๋‹ค์Œ ๋‹จ๊ณ„์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด๋‹น ์‚ฌ์šฉ์ž์˜ ์‚ฌ์šฉ์ž ์ด๋ฆ„๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•ˆ์ „ํ•œ ์œ„์น˜์— ์ €์žฅํ•˜์„ธ์š”.

์ด ๋‹จ๊ณ„๋ฅผ ์™„๋ฃŒํ•˜๋ฉด Atlas์— ์ƒˆ๋กœ์šด ํ”„๋ฆฌ ํ‹ฐ์–ด MongoDB ๋ฐฐํฌ์„œ๋ฒ„, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‚ฌ์šฉ์ž ์ž๊ฒฉ ์ฆ๋ช… ๋ฐ ์ƒ˜ํ”Œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋กœ๋“œ๋ฉ๋‹ˆ๋‹ค.

์—ฐ๊ฒฐ ๋ฌธ์ž์—ด์ด๋ผ๊ณ ๋„ ํ•˜๋Š” ์—ฐ๊ฒฐ URI์„ ์ œ๊ณตํ•˜์—ฌ MongoDB ๋ฐฐํฌ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด์€ ๋“œ๋ผ์ด๋ฒ„์— MongoDB ๋ฐฐํฌ์„œ๋ฒ„๋กœ ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ ์—ฐ๊ฒฐ๋œ ๋™์•ˆ ๋™์ž‘ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค.

์—ฐ๊ฒฐ ๋ฌธ์ž์—ด์—๋Š” ๋ฐฐํฌ์„œ๋ฒ„์˜ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„ ๋˜๋Š” IP ์ฃผ์†Œ์™€ ํฌํŠธ, ์ธ์ฆ ๋ฉ”์ปค๋‹ˆ์ฆ˜, ํ•ด๋‹น๋˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž ์ž๊ฒฉ ์ฆ๋ช…, ์—ฐ๊ฒฐ ์˜ต์…˜ ๋“ฑ์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.

Atlas ์—์„œ ํ˜ธ์ŠคํŒ…๋˜์ง€ ์•Š๋Š” ์ธ์Šคํ„ด์Šค ๋˜๋Š” ๋ฐฐํฌ์„œ๋ฒ„ ์— ์—ฐ๊ฒฐํ•˜๋ ค๋ฉด ์—ฐ๊ฒฐ ๋Œ€์ƒ ์„ ํƒ ๊ฐ€์ด๋“œ ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

1

์ด์ „ ๋‹จ๊ณ„์—์„œ ๋งŒ๋“  ๋ฐฐํฌ์„œ๋ฒ„์— ๋Œ€ํ•œ ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด ์กฐํšŒ ํ•˜๋ ค๋ฉด Atlas ๊ณ„์ •์— ๋กœ๊ทธ์ธ Database ์„น์…˜์œผ๋กœ ์ด๋™ํ•œ ๋‹ค์Œ ์ƒˆ ๋ฐฐํฌ์„œ๋ฒ„์— ๋Œ€ํ•œ Connect ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

The connect button in the clusters section of the Atlas UI

Connect your application ์„น์…˜์œผ๋กœ ์ด๋™ํ•˜์—ฌ Driver ์„ ํƒ ๋ฉ”๋‰ด์—์„œ "C"๋ฅผ ์„ ํƒํ•˜๊ณ  Version ์„ ํƒ ๋ฉ”๋‰ด์—์„œ ์„ค์น˜ํ•œ ๋ฒ„์ „๊ณผ ๊ฐ€์žฅ ์ผ์น˜ํ•˜๋Š” ๋ฒ„์ „์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

Password (SCRAM) ์ธ์ฆ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

์—ฐ๊ฒฐ string ๋งŒ ๋ณด๋ ค๋ฉด Include full driver code example ์˜ต์…˜์„ ์„ ํƒ ์ทจ์†Œํ•ฉ๋‹ˆ๋‹ค.

2

๋‹ค์Œ ์Šคํฌ๋ฆฐ์ƒท๊ณผ ๊ฐ™์ด ์—ฐ๊ฒฐ string ์˜ค๋ฅธ์ชฝ์— ์žˆ๋Š” ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ํด๋ฆฝ๋ณด๋“œ์— ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

The copy button next to the connection string in the Atlas UI
3

์ด ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด์„ ์›ํ•˜๋Š” ํ…์ŠคํŠธ ํŽธ์ง‘๊ธฐ์˜ ํŒŒ์ผ์— ๋ถ™์—ฌ๋„ฃ๊ณ  <db_username> ๋ฐ <db_password> ์ž๋ฆฌ ํ‘œ์‹œ์ž๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‚ฌ์šฉ์ž์˜ ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

๋‹ค์Œ ๋‹จ๊ณ„์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ด ํŒŒ์ผ์„ ์•ˆ์ „ํ•œ ์œ„์น˜์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

์ด ๋‹จ๊ณ„๋ฅผ ์™„๋ฃŒํ•˜๋ฉด ํด๋Ÿฌ์Šคํ„ฐ ์— ํ•ด๋‹นํ•˜๋Š” ์—ฐ๊ฒฐ string Atlas ์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

MongoDB deployment ์— ์—ฐ๊ฒฐํ•˜๊ณ  sample_mflix ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์˜ movies ์ปฌ๋ ‰์…˜ ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sample_mflix ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋Œ€ํ•ด ์ž์„ธํžˆ ํ•™์Šตํ•˜๋ ค๋ฉด Atlas ์„ค๋ช…์„œ์—์„œ ์ƒ˜ํ”Œ Mflix ๋ฐ์ดํ„ฐ ์„ธํŠธ ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

1

์…ธ ์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๋ ค๋Š” ์œ„์น˜๋กœ ์ด๋™ํ•œ ํ›„ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ ์ด ํ”„๋กœ์ ํŠธ ์— ๋Œ€ํ•ด c-quickstart ๋””๋ ‰ํ† ๋ฆฌ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

mkdir c-quickstart

์šด์˜ ์ฒด์ œ์— ํ•ด๋‹นํ•˜๋Š” ํƒญ ์„ ์„ ํƒํ•˜๊ณ  ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜์—ฌ c-quickstart ๋””๋ ‰ํ† ๋ฆฌ ์— quickstart.c ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํŒŒ์ผ ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

cd c-quickstart
touch quickstart.c
cd c-quickstart
type nul > quickstart.c
2

๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ sample_mflix ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์˜ movies ์ปฌ๋ ‰์…˜ ์„ ์ฟผ๋ฆฌํ•˜๋Š” quickstart.c ํŒŒ์ผ ์— ๋ถ™์—ฌ๋„ฃ์Šต๋‹ˆ๋‹ค.

#include <bson/bson.h>
#include <mongoc/mongoc.h>
#include <stdio.h>
int
main (void)
{
const bson_t *doc;
mongoc_init ();
mongoc_client_t *client = mongoc_client_new ("<connection string>");
mongoc_collection_t *collection = mongoc_client_get_collection (client, "sample_mflix", "movies");
// Specify the query filter
bson_t *query = BCON_NEW ("title", "The Shawshank Redemption");
mongoc_cursor_t *results = mongoc_collection_find_with_opts (collection, query, NULL, NULL);
// Print the results
while (mongoc_cursor_next (results, &doc))
{
char* str = bson_as_canonical_extended_json (doc, NULL);
printf ("%s\n", str);
bson_free (str);
}
bson_destroy (query);
mongoc_cursor_destroy (results);
mongoc_collection_destroy (collection);
mongoc_client_destroy (client);
mongoc_cleanup ();
return EXIT_SUCCESS;
}
3

<connection string> ์ž๋ฆฌ ํ‘œ์‹œ์ž๋ฅผ ์ด ๊ฐ€์ด๋“œ์˜ ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ ๋‹จ๊ณ„์—์„œ ๋ณต์‚ฌํ•œ ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

4

shell ์—์„œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜์—ฌ ์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ ์ปดํŒŒ์ผํ•˜๊ณ  ์‹คํ–‰ ํ•ฉ๋‹ˆ๋‹ค.

gcc -o quickstartc quickstart.c $(pkg-config --libs --cflags libmongoc-1.0)
./quickstartc

๋ช…๋ น์ค„ ์ถœ๋ ฅ์—๋Š” ๊ฒ€์ƒ‰๋œ ์˜ํ™” ๋ฌธ์„œ์— ๋Œ€ํ•œ ์„ธ๋ถ€ ์ •๋ณด๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.

{ "_id" : { "$oid" : "..." },
"plot" : "Two imprisoned men bond over a number of years, finding solace
and eventual redemption through acts of common decency.",
...
"title" : "The Shawshank Redemption",
...

์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๊ฑฐ๋‚˜ ์ถœ๋ ฅ์ด ํ‘œ์‹œ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ quickstart.c ํŒŒ์ผ์— ์ ์ ˆํ•œ ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด์„ ์ง€์ •ํ–ˆ๋Š”์ง€, ๊ทธ๋ฆฌ๊ณ  ์ƒ˜ํ”Œ ๋ฐ์ดํ„ฐ๋ฅผ ๋กœ๋“œํ–ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

์ด ๋‹จ๊ณ„๋ฅผ ์™„๋ฃŒํ•œ ํ›„์—๋Š” ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ MongoDB deployment์— ์—ฐ๊ฒฐํ•˜๊ณ , ์ƒ˜ํ”Œ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜๊ณ , ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋“ฑ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐ–๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋น ๋ฅธ ์‹œ์ž‘ ํŠœํ† ๋ฆฌ์–ผ์„ ์™„๋ฃŒํ•˜์‹  ๊ฒƒ์„ ์ถ•ํ•˜๋“œ๋ฆฝ๋‹ˆ๋‹ค!

์ฐธ๊ณ 

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ ๋ฌธ์ œ๊ฐ€ ์‹คํ–‰ ํ•˜๋ฉด MongoDB Community ํฌ๋Ÿผ ์—์„œ ๋„์›€์„ ์š”์ฒญํ•˜๊ฑฐ๋‚˜ ์ด ํŽ˜์ด์ง€์˜ ์˜ค๋ฅธ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํ•˜๋‹จ์— ์žˆ๋Š” Rate this page ํƒญ ์‚ฌ์šฉํ•˜์—ฌ ํ”ผ๋“œ๋ฐฑ ์ œ์ถœ .

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” MongoDB Atlas ์—์„œ ํ˜ธ์ŠคํŒ…๋˜๋Š” MongoDB deployment ์— ์—ฐ๊ฒฐํ•˜๊ณ  ์ฟผ๋ฆฌ ์™€ ์ผ์น˜ํ•˜๋Š” ๋ฌธ์„œ ๊ฒ€์ƒ‰ํ•˜๋Š” C ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ๋ฆฌ์†Œ์Šค์—์„œ C ์šด์ „์ž ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ๋ณด๊ธฐ .