{"id":91549,"date":"2025-09-27T22:04:32","date_gmt":"2025-09-27T15:04:32","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=91549"},"modified":"2025-09-27T22:05:08","modified_gmt":"2025-09-27T15:05:08","slug":"lo-trinh-hoc-tap-mongodb-tutorial","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/","title":{"rendered":"MongoDB tutorial c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn c\u00e1c b\u01b0\u1edbc h\u1ecdc MongoDB to\u00e0n di\u1ec7n"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#MongoDB_tutorial_buoc_1_Hieu_ro_ve_ban_chat_cua_MongoDB\" >MongoDB tutorial b\u01b0\u1edbc 1: Hi\u1ec3u r\u00f5 v\u1ec1 b\u1ea3n ch\u1ea5t c\u1ee7a MongoDB<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#MongoDB_tutorial_buoc_2_Lam_quen_cac_khai_niem_cot_loi\" >MongoDB tutorial b\u01b0\u1edbc 2: L\u00e0m quen c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#MongoDB_tutorial_buoc_3_Thuc_hanh_cac_thao_tac_co_ban\" >MongoDB tutorial b\u01b0\u1edbc 3: Th\u1ef1c h\u00e0nh c\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#MongoDB_tutorial_buoc_4_Thuc_hanh_MongoDB_nang_cao\" >MongoDB tutorial b\u01b0\u1edbc 4: Th\u1ef1c h\u00e0nh MongoDB n\u00e2ng cao<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#MongoDB_tutorial_buoc_5_Tim_hieu_cach_xu_ly_loi_thuong_gap_trong_MongoDB\" >MongoDB tutorial b\u01b0\u1edbc 5: T\u00ecm hi\u1ec3u c\u00e1ch x\u1eed l\u00fd l\u1ed7i th\u01b0\u1eddng g\u1eb7p trong MongoDB<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#Cau_hoi_thuong_gap_ve_MongoDB_tutorial\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 MongoDB tutorial<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#Tong_ket\" >T\u1ed5ng k\u1ebft<\/a><\/li><\/ul><\/nav><\/div>\n\n<p><strong><em>MongoDB l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 m\u1ea1nh m\u1ebd, nh\u01b0ng \u0111\u1ec3 khai th\u00e1c h\u1ebft s\u1ee9c m\u1ea1nh c\u1ee7a n\u00f3 th\u00ec b\u1ea1n c\u1ea7n nhi\u1ec1u h\u01a1n l\u00e0 \u201ch\u1ecdc thu\u1ed9c c\u00e2u l\u1ec7nh\u201d. \u0110\u1ec3 h\u1ecdc MongoDB hi\u1ec7u qu\u1ea3, b\u1ea1n c\u1ea7n t\u01b0 duy theo h\u01b0\u1edbng d\u1eef li\u1ec7u phi c\u1ea5u tr\u00fac v\u00e0 bi\u1ebft c\u00e1ch x\u00e2y d\u1ef1ng l\u1ed9 tr\u00ecnh h\u1ecdc t\u1eadp h\u1ee3p l\u00fd \u0111\u1ec3 kh\u00f4ng b\u1ecb &#8220;r\u1ed1i n\u00e3o&#8221; khi b\u01b0\u1edbc v\u00e0o nh\u1eefng kh\u00e1i ni\u1ec7m n\u00e2ng cao h\u01a1n nh\u01b0 aggregation pipeline, indexing, hay schema design. B\u00e0i vi\u1ebft MongoDB tutorial d\u01b0\u1edbi \u0111\u00e2y s\u1ebd h\u01b0\u1edbng d\u1eabn b\u1ea1n t\u00ecm hi\u1ec3u v\u1ec1 MongoDB theo m\u1ed9t l\u1ed9 tr\u00ecnh h\u1ee3p l\u00fd v\u00e0 d\u1ec5 hi\u1ec3u nh\u1ea5t.<\/em><\/strong><\/p>\n\n\n\n<p>\u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hi\u1ec3u MongoDB l\u00e0 g\u00ec v\u00e0 v\u00ec sao ng\u00e0y c\u00e0ng ph\u1ed5 bi\u1ebfn trong c\u00e1c h\u1ec7 th\u1ed1ng hi\u1ec7n \u0111\u1ea1i<\/li>\n\n\n\n<li>N\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i c\u1ee7a MongoDB<\/li>\n\n\n\n<li>Th\u1ef1c h\u00e0nh c\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n<\/li>\n\n\n\n<li>H\u1ecdc c\u00e1ch x\u1eed l\u00fd l\u1ed7i th\u01b0\u1eddng g\u1eb7p khi l\u00e0m vi\u1ec7c v\u1edbi MongoDB&nbsp;<\/li>\n\n\n\n<li>L\u1ed9 tr\u00ecnh h\u1ecdc l\u00ean c\u00e1c ch\u1ee7 \u0111\u1ec1 n\u00e2ng cao nh\u01b0 indexing, aggregation, schema design,&#8230;<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-mongodb-tutorial-b\u01b0\u1edbc-1-hi\u1ec3u-ro-v\u1ec1-b\u1ea3n-ch\u1ea5t-c\u1ee7a-mongodb\"><span class=\"ez-toc-section\" id=\"MongoDB_tutorial_buoc_1_Hieu_ro_ve_ban_chat_cua_MongoDB\"><\/span><strong>MongoDB tutorial b\u01b0\u1edbc 1: Hi\u1ec3u r\u00f5 v\u1ec1 b\u1ea3n ch\u1ea5t c\u1ee7a MongoDB<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>MongoDB l\u00e0 m\u1ed9t h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u NoSQL d\u1ea1ng document-oriented (d\u1ef1a tr\u00ean t\u00e0i li\u1ec7u), \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf \u0111\u1ec3 x\u1eed l\u00fd d\u1eef li\u1ec7u phi c\u1ea5u tr\u00fac v\u00e0 b\u00e1n c\u1ea5u tr\u00fac m\u1ed9t c\u00e1ch linh ho\u1ea1t v\u00e0 hi\u1ec7u qu\u1ea3. Kh\u00e1c v\u1edbi c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 (RDBMS) truy\u1ec1n th\u1ed1ng l\u01b0u tr\u1eef d\u1eef li\u1ec7u theo b\u1ea3ng, MongoDB l\u01b0u tr\u1eef d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng BSON documents (Binary JSON) v\u00e0 cho ph\u00e9p bi\u1ec3u di\u1ec5n d\u1eef li\u1ec7u ph\u1ee9c t\u1ea1p nh\u01b0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>M\u1ea3ng (arrays)<\/li>\n\n\n\n<li>\u0110\u1ed1i t\u01b0\u1ee3ng l\u1ed3ng nhau (nested objects)<\/li>\n\n\n\n<li>Nhi\u1ec1u ki\u1ec3u d\u1eef li\u1ec7u \u0111a d\u1ea1ng kh\u00e1c<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-m\u1ed9t-s\u1ed1-di\u1ec3m-n\u1ed5i-b\u1eadt-c\u1ee7a-mongodb\"><strong>M\u1ed9t s\u1ed1 \u0111i\u1ec3m n\u1ed5i b\u1eadt c\u1ee7a MongoDB<\/strong><\/h3>\n\n\n\n<p>MongoDB \u0111\u01b0\u1ee3c \u01b0a chu\u1ed9ng kh\u00f4ng ch\u1ec9 nh\u1edd kh\u1ea3 n\u0103ng l\u01b0u tr\u1eef linh ho\u1ea1t, m\u00e0 c\u00f2n v\u00ec n\u00f3 t\u00edch h\u1ee3p s\u1eb5n nhi\u1ec1u t\u00ednh n\u0103ng query m\u1ea1nh m\u1ebd nh\u01b0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>T\u00ecm ki\u1ebfm v\u0103n b\u1ea3n (text search)<\/li>\n\n\n\n<li>D\u1eef li\u1ec7u kh\u00f4ng gian \u0111\u1ecba l\u00fd (geospatial queries)<\/li>\n\n\n\n<li>Aggregation framework (m\u1ed9t c\u01a1 ch\u1ebf x\u1eed l\u00fd, bi\u1ebfn \u0111\u1ed5i v\u00e0 ph\u00e2n t\u00edch d\u1eef li\u1ec7u theo t\u1eebng b\u01b0\u1edbc gi\u1ed1ng nh\u01b0 \u201cd\u00e2y chuy\u1ec1n x\u1eed l\u00fd\u201d), cho ph\u00e9p ph\u00e2n t\u00edch v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u ph\u1ee9c t\u1ea1p.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>V\u1edbi thi\u1ebft k\u1ebf schema-less (kh\u00f4ng y\u00eau c\u1ea7u l\u01b0\u1ee3c \u0111\u1ed3 c\u1ed1 \u0111\u1ecbnh), MongoDB \u0111\u1eb7c bi\u1ec7t ph\u00f9 h\u1ee3p cho c\u00e1c \u1ee9ng d\u1ee5ng c\u1ea7n ph\u00e1t tri\u1ec3n nhanh, thay \u0111\u1ed5i linh ho\u1ea1t c\u1ea5u tr\u00fac d\u1eef li\u1ec7u v\u00e0 m\u1edf r\u1ed9ng quy m\u00f4 d\u1ec5 d\u00e0ng.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-l\u1ee3i-ich-khi-s\u1eed-d\u1ee5ng-mongodb\"><strong>L\u1ee3i \u00edch khi s\u1eed d\u1ee5ng MongoDB<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>D\u1ec5 m\u1edf r\u1ed9ng (Scalable):<\/strong> MongoDB h\u1ed7 tr\u1ee3 sharding (chia nh\u1ecf d\u1eef li\u1ec7u v\u00e0 ph\u00e2n t\u00e1n qua nhi\u1ec1u m\u00e1y ch\u1ee7), gi\u00fap h\u1ec7 th\u1ed1ng x\u1eed l\u00fd t\u1ed1t d\u1eef li\u1ec7u l\u1edbn v\u00e0 l\u01b0\u1ee3ng truy c\u1eadp cao.<\/li>\n\n\n\n<li><strong>Linh ho\u1ea1t (Flexible schema):<\/strong> Kh\u00f4ng y\u00eau c\u1ea7u l\u01b0\u1ee3c \u0111\u1ed3 c\u1ed1 \u0111\u1ecbnh nh\u01b0 SQL, cho ph\u00e9p ng\u01b0\u1eddi d\u00f9ng d\u1ec5 d\u00e0ng thay \u0111\u1ed5i c\u1ea5u tr\u00fac d\u1eef li\u1ec7u khi \u1ee9ng d\u1ee5ng ph\u00e1t tri\u1ec3n.<\/li>\n\n\n\n<li><strong>H\u1ed7 tr\u1ee3 \u0111a d\u1ea1ng t\u00ednh n\u0103ng m\u1ea1nh m\u1ebd<\/strong>: Bao g\u1ed3m t\u00ecm ki\u1ebfm v\u0103n b\u1ea3n (text search), truy v\u1ea5n \u0111\u1ecba l\u00fd (geospatial queries) v\u00e0 aggregation pipeline \u0111\u1ec3 x\u1eed l\u00fd d\u1eef li\u1ec7u ph\u1ee9c t\u1ea1p.<\/li>\n\n\n\n<li><strong>Kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i v\u00e0 t\u00ednh s\u1eb5n s\u00e0ng cao (High availability)<\/strong>: Nh\u1edd c\u01a1 ch\u1ebf replication (sao ch\u00e9p d\u1eef li\u1ec7u sang nhi\u1ec1u m\u00e1y ch\u1ee7), d\u1eef li\u1ec7u lu\u00f4n an to\u00e0n v\u00e0 h\u1ec7 th\u1ed1ng c\u00f3 th\u1ec3 ti\u1ebfp t\u1ee5c ch\u1ea1y n\u1ebfu m\u1ed9t m\u00e1y ch\u1ee7 g\u1eb7p s\u1ef1 c\u1ed1.<\/li>\n\n\n\n<li><strong>D\u1ec5 d\u00e0ng t\u00edch h\u1ee3p<\/strong>: MongoDB l\u01b0u tr\u1eef d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng BSON\/JSON n\u00ean g\u1ea7n g\u0169i v\u1edbi c\u00e1ch l\u1eadp tr\u00ecnh hi\u1ec7n \u0111\u1ea1i, d\u1ec5 t\u00edch h\u1ee3p v\u1edbi nhi\u1ec1u ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh ph\u1ed5 bi\u1ebfn nh\u01b0 Python, Node.js.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-h\u1ea1n-ch\u1ebf-c\u1ee7a-mongodb\"><strong>H\u1ea1n ch\u1ebf c\u1ee7a MongoDB<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>T\u1ed1n nhi\u1ec1u t\u00e0i nguy\u00ean:<\/strong> V\u00ec ho\u1ea1t \u0111\u1ed9ng t\u1ed1i \u01b0u v\u1edbi d\u1eef li\u1ec7u l\u01b0u trong RAM, MongoDB c\u00f3 th\u1ec3 ng\u1ed1n nhi\u1ec1u b\u1ed9 nh\u1edb khi d\u1eef li\u1ec7u v\u00e0 truy v\u1ea5n tr\u1edf n\u00ean l\u1edbn.<\/li>\n\n\n\n<li><strong>Thi\u1ebfu chu\u1ea9n ACID:<\/strong> M\u1eb7c d\u00f9 c\u00f3 h\u1ed7 tr\u1ee3 transaction (giao d\u1ecbch) nh\u01b0ng kh\u00f4ng m\u1ea1nh m\u1ebd b\u1eb1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7, n\u00ean c\u00f3 th\u1ec3 ch\u01b0a ph\u00f9 h\u1ee3p v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng t\u00e0i ch\u00ednh ho\u1eb7c ho\u1eb7c c\u00e1c \u1ee9ng d\u1ee5ng y\u00eau c\u1ea7u t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u tuy\u1ec7t \u0111\u1ed1i.<\/li>\n\n\n\n<li><strong>Qu\u1ea3n tr\u1ecb ph\u1ee9c t\u1ea1p h\u01a1n khi d\u1eef li\u1ec7u r\u1ea5t l\u1edbn:<\/strong> Vi\u1ec7c tri\u1ec3n khai sharding hay tinh ch\u1ec9nh hi\u1ec7u su\u1ea5t ph\u1ee9c t\u1ea1p n\u00ean \u0111\u00f2i h\u1ecfi \u0111\u1ed9i ng\u0169 nh\u00e2n l\u1ef1c d\u00e0y d\u1eb7n kinh nghi\u1ec7m.<\/li>\n\n\n\n<li><strong>\u00cdt ph\u00f9 h\u1ee3p cho c\u00e1c h\u1ec7 th\u1ed1ng c\u1ea7n nhi\u1ec1u m\u1ed1i quan h\u1ec7 ph\u1ee9c t\u1ea1p:<\/strong> Kh\u00f4ng m\u1ea1nh b\u1eb1ng SQL trong x\u1eed l\u00fd join ph\u1ee9c t\u1ea1p.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>\u0110\u1ecdc chi ti\u1ebft: <strong><a href=\"https:\/\/itviec.com\/blog\/mongodb-la-gi\/\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB l\u00e0 g\u00ec? \u0110\u1ecbnh ngh\u0129a v\u00e0 Hi\u1ec3u r\u00f5 A-Z v\u1ec1 MongoDB<\/a><\/strong><\/em><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-mongodb-tutorial-b\u01b0\u1edbc-2-lam-quen-cac-khai-ni\u1ec7m-c\u1ed1t-loi\"><span class=\"ez-toc-section\" id=\"MongoDB_tutorial_buoc_2_Lam_quen_cac_khai_niem_cot_loi\"><\/span><strong>MongoDB tutorial b\u01b0\u1edbc 2: L\u00e0m quen c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Tr\u01b0\u1edbc khi b\u1eaft tay v\u00e0o vi\u1ebft l\u1ec7nh hay thao t\u00e1c v\u1edbi MongoDB, b\u1ea1n c\u1ea7n hi\u1ec3u r\u00f5 nh\u1eefng kh\u00e1i ni\u1ec7m n\u1ec1n t\u1ea3ng t\u1ea1o n\u00ean c\u1ea5u tr\u00fac c\u1ee7a h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u n\u00e0y.<\/p>\n\n\n\n<p>D\u01b0\u1edbi \u0111\u00e2y l\u00e0 c\u00e1c th\u00e0nh ph\u1ea7n c\u01a1 b\u1ea3n b\u1ea1n c\u1ea7n n\u1eafm v\u1eefng:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Database (C\u01a1 s\u1edf d\u1eef li\u1ec7u):<\/strong> N\u01a1i l\u01b0u tr\u1eef t\u1eadp h\u1ee3p c\u00e1c collections (m\u1ed9t instance MongoDB c\u00f3 th\u1ec3 ch\u1ee9a nhi\u1ec1u databases kh\u00e1c nhau).<\/li>\n\n\n\n<li><strong>Collection:<\/strong> T\u01b0\u01a1ng t\u1ef1 nh\u01b0 b\u1ea3ng (table) trong SQL, nh\u01b0ng kh\u00f4ng c\u1ea7n schema c\u1ed1 \u0111\u1ecbnh. M\u1ed9t collection c\u00f3 th\u1ec3 ch\u1ee9a nhi\u1ec1u document v\u1edbi c\u00e1c tr\u01b0\u1eddng (field) kh\u00e1c nhau.<\/li>\n\n\n\n<li><strong>Document (T\u00e0i li\u1ec7u)<\/strong>: m\u1ed9t b\u1ea3n ghi d\u1eef li\u1ec7u, \u0111\u01b0\u1ee3c l\u01b0u d\u01b0\u1edbi d\u1ea1ng JSON\/BSON (v\u00ed d\u1ee5: <code>{name: \"John\", age: 25}<\/code>).<\/li>\n\n\n\n<li><strong>Field<\/strong>: C\u1eb7p key-value trong document (t\u01b0\u01a1ng t\u1ef1 column trong SQL). V\u00ed d\u1ee5 v\u1edbi document <code>{name: \"John\", age: 25}<\/code> th\u00ec <code>\"name\"<\/code> v\u00e0 <code>\"age\"<\/code> l\u00e0 c\u00e1c field, v\u1edbi gi\u00e1 tr\u1ecb l\u1ea7n l\u01b0\u1ee3t l\u00e0 <code>\"John\"<\/code> v\u00e0 <code>25<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-mongodb-tutorial-b\u01b0\u1edbc-3-th\u1ef1c-hanh-cac-thao-tac-c\u01a1-b\u1ea3n\"><span class=\"ez-toc-section\" id=\"MongoDB_tutorial_buoc_3_Thuc_hanh_cac_thao_tac_co_ban\"><\/span><strong>MongoDB tutorial b\u01b0\u1edbc 3: Th\u1ef1c h\u00e0nh c\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u0110\u1ec3 c\u00f3 th\u1ec3 th\u1ef1c h\u00e0nh c\u00e1c thao t\u00e1c v\u1edbi MongoDB, tr\u01b0\u1edbc ti\u00ean b\u1ea1n c\u1ea7n c\u00e0i \u0111\u1eb7t MongoDB tr\u00ean m\u00e1y t\u00ednh c\u1ee7a m\u00ecnh v\u00e0 b\u1ea1n c\u00f3 th\u1ec3 tham kh\u1ea3o c\u00e1ch c\u00e0i \u0111\u1eb7t MongoDB t\u1ea1i \u0111\u00e2y.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-lam-quen-v\u1edbi-mongodb-shell-mongosh\"><strong>L\u00e0m quen v\u1edbi MongoDB Shell (mongosh)<\/strong><\/h3>\n\n\n\n<p>Tr\u01b0\u1edbc khi l\u00e0m vi\u1ec7c v\u1edbi d\u1eef li\u1ec7u, b\u1ea1n c\u1ea7n bi\u1ebft c\u00e1ch t\u01b0\u01a1ng t\u00e1c v\u1edbi MongoDB qua Shell. Shell l\u00e0 m\u00f4i tr\u01b0\u1eddng d\u00f2ng l\u1ec7nh n\u01a1i b\u1ea1n c\u00f3 th\u1ec3 nh\u1eadp tr\u1ef1c ti\u1ebfp c\u00e1c l\u1ec7nh \u0111\u1ec3 \u0111i\u1ec1u khi\u1ec3n c\u01a1 s\u1edf d\u1eef li\u1ec7u. Vi\u1ec7c quen v\u1edbi Shell gi\u00fap b\u1ea1n n\u1eafm \u0111\u01b0\u1ee3c c\u00e1ch MongoDB ph\u1ea3n h\u1ed3i v\u00e0 hi\u1ec3u c\u1ea5u tr\u00fac d\u1eef li\u1ec7u ngay t\u1eeb \u0111\u1ea7u. V\u00ed d\u1ee5 \u0111\u1ec3 xem danh s\u00e1ch s\u00e1ch c\u01a1 s\u1edf d\u1eef li\u1ec7u hi\u1ec7n c\u00f3 nh\u01b0 sau:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u0110\u1ea7u ti\u00ean m\u1edf Terminal v\u00e0 truy c\u1eadp MongoDB: \nMongosh\n\n# Ho\u1eb7c k\u1ebft n\u1ed1i \u0111\u1ebfn specific database\/host:\nmongosh \"mongodb:\/\/localhost:27017\/myDatabase\"\n\n# Xem danh s\u00e1ch CSDL hi\u1ec7n c\u00f3\nshow dbs\n\n# Xem database hi\u1ec7n t\u1ea1i\ndb\n\n# Xem collections trong database hi\u1ec7n t\u1ea1i\nshow collections<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-t\u1ea1o-c\u01a1-s\u1edf-d\u1eef-li\u1ec7u-va-collection\"><strong>T\u1ea1o c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 collection<\/strong><\/h3>\n\n\n\n<p>M\u1ed9t database trong MongoDB gi\u1ed1ng nh\u01b0 \u201cng\u00f4i nh\u00e0\u201d ch\u1ee9a c\u00e1c collection, c\u00f2n collection ch\u00ednh l\u00e0 \u201cph\u00f2ng\u201d \u0111\u1ec3 l\u01b0u tr\u1eef t\u00e0i li\u1ec7u (document). V\u00ed d\u1ee5 \u0111\u1ec3 t\u1ea1o m\u1ed9t database t\u00ean <em>tutorialDB<\/em> v\u00e0 m\u1ed9t collection t\u00ean <em>users<\/em> ta d\u00f9ng c\u00fa ph\u00e1p nh\u01b0 sau:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use tutorialDB\ndb.createCollection(\"users\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-them-d\u1eef-li\u1ec7u-d\u1ea7u-tien-crud-create\"><strong>Th\u00eam d\u1eef li\u1ec7u \u0111\u1ea7u ti\u00ean (CRUD &#8211; Create)<\/strong><\/h3>\n\n\n\n<p>MongoDB l\u01b0u d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng document (t\u00e0i li\u1ec7u) \u1edf \u0111\u1ecbnh d\u1ea1ng JSON. M\u1ed7i document c\u00f3 th\u1ec3 linh ho\u1ea1t v\u1ec1 c\u1ea5u tr\u00fac, kh\u00f4ng c\u1ea7n r\u00e0ng bu\u1ed9c c\u1ee9ng nh\u01b0 b\u1ea3ng trong SQL. V\u00ed d\u1ee5 \u0111\u1ec3 l\u01b0u th\u00f4ng tin m\u1ed9t ng\u01b0\u1eddi d\u00f9ng v\u00e0o collection <em>users<\/em> ta d\u00f9ng:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>db.users.insertOne({ name: \"Alice\", age: 25, email: \"alice@example.com\" })\n\n\/\/ Insert nhi\u1ec1u documents c\u00f9ng l\u00fac\ndb.users.insertMany(&#91;\n    { name: \"Bob\", age: 30, email: \"bob@example.com\" },\n    { name: \"Charlie\", age: 28, email: \"charlie@example.com\" }\n])<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-truy-v\u1ea5n-d\u1eef-li\u1ec7u\"><strong>Truy v\u1ea5n d\u1eef li\u1ec7u<\/strong><\/h3>\n\n\n\n<p>\u0110i\u1ec3m m\u1ea1nh c\u1ee7a MongoDB l\u00e0 kh\u1ea3 n\u0103ng truy v\u1ea5n linh ho\u1ea1t. B\u1ea1n c\u00f3 th\u1ec3 l\u1ecdc, t\u00ecm ki\u1ebfm d\u1ef1a tr\u00ean nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n kh\u00e1c nhau, t\u01b0\u01a1ng t\u1ef1 nh\u01b0 vi\u1ec7c \u201ch\u1ecfi\u201d c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u1ec3 l\u1ea5y th\u00f4ng tin mong mu\u1ed1n. V\u00ed d\u1ee5 \u0111\u1ec3 t\u00ecm t\u1ea5t c\u1ea3 ng\u01b0\u1eddi d\u00f9ng c\u00f3 tu\u1ed5i l\u1edbn h\u01a1n 20 ta d\u00f9ng c\u00fa ph\u00e1p:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ T\u00ecm t\u1ea5t c\u1ea3 documents\ndb.users.find()\n\n\/\/ T\u00ecm v\u1edbi \u0111i\u1ec1u ki\u1ec7n\ndb.users.find({ age: { $gt: 20 } })\n\n\/\/ C\u00e1c query operators ph\u1ed5 bi\u1ebfn:\ndb.users.find({ age: { $gte: 25, $lte: 30 } })  \/\/ 25 &lt;= age &lt;= 30\ndb.users.find({ name: { $in: &#91;\"Alice\", \"Bob\"] } })  \/\/ name trong danh s\u00e1ch\ndb.users.find({ email: { $regex: \/gmail\/ } })  \/\/ email ch\u1ee9a \"gmail\"\n\n\/\/ Projection - ch\u1ec9 l\u1ea5y c\u00e1c field c\u1ea7n thi\u1ebft\ndb.users.find({}, { name: 1, email: 1, _id: 0 })\n\n\/\/ Sorting v\u00e0 limiting\ndb.users.find().sort({ age: -1 }).limit(2)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-c\u1eadp-nh\u1eadt-va-xoa-d\u1eef-li\u1ec7u\"><strong>C\u1eadp nh\u1eadt v\u00e0 x\u00f3a d\u1eef li\u1ec7u<\/strong><\/h3>\n\n\n\n<p>D\u1eef li\u1ec7u trong MongoDB kh\u00f4ng ph\u1ea3i c\u1ed1 \u0111\u1ecbnh, ta c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng c\u1eadp nh\u1eadt ho\u1eb7c x\u00f3a khi c\u1ea7n, gi\u00fap duy tr\u00ec d\u1eef li\u1ec7u lu\u00f4n \u0111\u00fang v\u1edbi th\u1ef1c t\u1ebf. V\u00ed d\u1ee5:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u0110\u1ec3 c\u1eadp nh\u1eadt tu\u1ed5i c\u1ee7a Alice: \ndb.users.updateOne({ name: \"Alice\" }, { $set: { age: 26 } })\n\n# Update nhi\u1ec1u documents\ndb.users.updateMany(\n    { age: { $lt: 30 } },\n    { $set: { status: \"young\" } }\n)\n\n# Upsert - update n\u1ebfu t\u1ed3n t\u1ea1i, insert n\u1ebfu kh\u00f4ng\ndb.users.updateOne(\n    { name: \"David\" },\n    { $set: { age: 35, email: \"david@example.com\" } },\n    { upsert: true }\n)\n\n\n# Xo\u00e1 b\u1ea3n ghi c\u1ee7a Alice:\ndb.users.deleteOne({ name: \"Alice\" })\n\n# X\u00f3a nhi\u1ec1u documents\ndb.users.deleteMany({ age: { $lt: 25 } })<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-t\u1ed5ng-h\u1ee3p-cac-l\u1ec7nh-c\u01a1-b\u1ea3n-trong-mongodb\"><strong>T\u1ed5ng h\u1ee3p c\u00e1c l\u1ec7nh c\u01a1 b\u1ea3n trong MongoDB<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>L\u1ec7nh<\/strong><\/td><td><strong>M\u1ee5c \u0111\u00edch<\/strong><\/td><td><strong>V\u00ed d\u1ee5<\/strong><\/td><\/tr><tr><td><code>show dbs<\/code><\/td><td>Li\u1ec7t k\u00ea t\u1ea5t c\u1ea3 c\u01a1 s\u1edf d\u1eef li\u1ec7u hi\u1ec7n c\u00f3<\/td><td><code>show dbs<\/code><br>=&gt; Hi\u1ec3n th\u1ecb danh s\u00e1ch c\u00e1c database c\u00f3 d\u1eef li\u1ec7u v\u00e0 c\u00f3 k\u00edch th\u01b0\u1edbc &gt; 0 trong MongoDB.<\/td><\/tr><tr><td><code>use &lt;dbName&gt;<\/code><\/td><td>Ch\u1ecdn ho\u1eb7c t\u1ea1o m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u<\/td><td><code>use tutorialDB<\/code><br>=&gt; N\u1ebfu tutorialDB ch\u01b0a t\u1ed3n t\u1ea1i, MongoDB s\u1ebd t\u1ea1o m\u1edbi khi b\u1ea1n th\u00eam d\u1eef li\u1ec7u.<\/td><\/tr><tr><td><code>db.createCollection()<\/code><\/td><td>T\u1ea1o m\u1ed9t collection (t\u01b0\u01a1ng t\u1ef1 \u201cb\u1ea3ng\u201d)<\/td><td><code>db.createCollection(\"users\")<\/code><br>=&gt; T\u1ea1o collection <code>users<\/code> trong database hi\u1ec7n t\u1ea1i.<\/td><\/tr><tr><td><code>db.&lt;collection&gt;.insertOne()<\/code><\/td><td>Th\u00eam m\u1ed9t document (b\u1ea3n ghi)<\/td><td><code>db.users.insertOne({ name: \"Alice\", age: 25 })<\/code><br>=&gt; Th\u00eam document v\u1edbi 2 field <code>name<\/code> v\u00e0 <code>age<\/code> v\u00e0o collection <code>users<\/code>. MongoDB s\u1ebd t\u1ef1 \u0111\u1ed9ng t\u1ea1o field _id (ObjectId) l\u00e0m primary key.<\/td><\/tr><tr><td><code>db.&lt;collection&gt;.find()<\/code><\/td><td>Truy v\u1ea5n d\u1eef li\u1ec7u<\/td><td><code>db.users.find({ age: { $gt: 20 } })<\/code><br>=&gt; L\u1ea5y t\u1ea5t c\u1ea3 ng\u01b0\u1eddi d\u00f9ng c\u00f3 tu\u1ed5i (<code>age<\/code>) &gt; 20.<\/td><\/tr><tr><td><code>db.&lt;collection&gt;.updateOne()<\/code><\/td><td>C\u1eadp nh\u1eadt d\u1eef li\u1ec7u<\/td><td><code>db.users.updateOne({ name: \"Alice\" }, { $set: { age: 26 } })<\/code><br>=&gt; T\u00ecm user c\u00f3 <code>name = Alice<\/code> v\u00e0 c\u1eadp nh\u1eadt <code>age<\/code> th\u00e0nh 26.<\/td><\/tr><tr><td><code>db.&lt;collection&gt;.deleteOne()<\/code><\/td><td>X\u00f3a d\u1eef li\u1ec7u<\/td><td><code>db.users.deleteOne({ name: \"Alice\" })<\/code><br>=&gt; X\u00f3a document c\u00f3 <code>name = Alice<\/code>.<\/td><\/tr><tr><td><code>db.&lt;collection&gt;.drop()<\/code><\/td><td>X\u00f3a collection<\/td><td><code>db.users.drop()<\/code><br>=&gt; X\u00f3a to\u00e0n b\u1ed9 collection <code>users<\/code>.<\/td><\/tr><tr><td><code>db.dropDatabase()<\/code><\/td><td>X\u00f3a database hi\u1ec7n t\u1ea1i<\/td><td><code>db.dropDatabase()<\/code><br>=&gt; X\u00f3a to\u00e0n b\u1ed9 database m\u00e0 b\u1ea1n \u0111ang ch\u1ecdn (<code>use<\/code>).<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-mongodb-tutorial-b\u01b0\u1edbc-4-th\u1ef1c-hanh-mongodb-nang-cao\"><span class=\"ez-toc-section\" id=\"MongoDB_tutorial_buoc_4_Thuc_hanh_MongoDB_nang_cao\"><\/span><strong>MongoDB tutorial b\u01b0\u1edbc 4: Th\u1ef1c h\u00e0nh MongoDB n\u00e2ng cao<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sau khi \u0111\u00e3 n\u1eafm ch\u1eafc c\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi MongoDB (t\u1ea1o database, collection, th\u00eam v\u00e0 truy v\u1ea5n d\u1eef li\u1ec7u), b\u1ea1n c\u00f3 th\u1ec3 ti\u1ebfp t\u1ee5c nghi\u00ean c\u1ee9u c\u00e1c ch\u1ee7 \u0111\u1ec1 n\u00e2ng cao h\u01a1n \u0111\u1ec3 \u1ee9ng d\u1ee5ng trong c\u00e1c h\u1ec7 th\u1ed1ng th\u1ef1c t\u1ebf:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-indexes-ch\u1ec9-m\u1ee5c\"><strong>Indexes (Ch\u1ec9 m\u1ee5c)<\/strong><\/h3>\n\n\n\n<p>Trong MongoDB, ch\u1ec9 m\u1ee5c (indexes) l\u00e0 c\u1ea5u tr\u00fac d\u1eef li\u1ec7u b-tree gi\u00fap t\u0103ng t\u1ed1c \u0111\u1ed9 t\u00ecm ki\u1ebfm. N\u1ebfu kh\u00f4ng c\u00f3 ch\u1ec9 m\u1ee5c, MongoDB s\u1ebd ph\u1ea3i qu\u00e9t to\u00e0n b\u1ed9 collection, g\u00e2y ch\u1eadm tr\u1ec5 khi d\u1eef li\u1ec7u l\u1edbn. C\u00e1c lo\u1ea1i ch\u1ec9 m\u1ee5c g\u1ed3m: ch\u1ec9 m\u1ee5c m\u1ed9t tr\u01b0\u1eddng (single field), ch\u1ec9 m\u1ee5c nhi\u1ec1u tr\u01b0\u1eddng (compound index), ch\u1ec9 m\u1ee5c to\u00e0n v\u0103n b\u1ea3n (text index), ch\u1ec9 m\u1ee5c \u0111\u1ecba l\u00fd (geospatial index).<\/p>\n\n\n\n<p>T\u00e0i li\u1ec7u tham kh\u1ea3o: <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/indexes\/\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB Indexes Docs<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-aggregation-framework\"><strong>Aggregation Framework<\/strong><\/h3>\n\n\n\n<p>Aggregation trong MongoDB gi\u1ed1ng nh\u01b0 &#8220;pipeline x\u1eed l\u00fd d\u1eef li\u1ec7u&#8221; g\u1ed3m c\u00e1c n\u1ed9i dung nh\u01b0 l\u1ecdc ($match), nh\u00f3m ($group), s\u1eafp x\u1ebfp ($sort) ho\u1eb7c th\u1eadm ch\u00ed n\u1ed1i d\u1eef li\u1ec7u t\u1eeb nhi\u1ec1u collection ($lookup) th\u01b0\u1eddng \u0111\u01b0\u1ee3c d\u00f9ng \u0111\u1ec3 x\u1eed l\u00fd d\u1eef li\u1ec7u ph\u1ee9c t\u1ea1p.<\/p>\n\n\n\n<p>T\u00e0i li\u1ec7u: <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/aggregation\/\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB Aggregation Docs<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-data-modeling-nang-cao\"><strong>Data Modeling n\u00e2ng cao<\/strong><\/h3>\n\n\n\n<p>MongoDB cho ph\u00e9p b\u1ea1n thi\u1ebft k\u1ebf d\u1eef li\u1ec7u theo c\u00e1ch linh ho\u1ea1t: nh\u00fang document (embed) trong nhau ho\u1eb7c tham chi\u1ebfu (reference) gi\u1eefa c\u00e1c collection.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Khi d\u1eef li\u1ec7u li\u00ean quan ch\u1eb7t ch\u1ebd =&gt; d\u00f9ng <strong>embed<\/strong>.<\/li>\n\n\n\n<li>Khi d\u1eef li\u1ec7u l\u1edbn, ho\u1eb7c quan h\u1ec7 ph\u1ee9c t\u1ea1p =&gt; d\u00f9ng <strong>reference<\/strong>.<\/li>\n\n\n\n<li>C\u00e1c pattern ph\u1ed5 bi\u1ebfn: One-to-Many, Many-to-Many, Bucket Pattern, Attribute Pattern.<\/li>\n<\/ul>\n\n\n\n<p>T\u00e0i li\u1ec7u: <a href=\"https:\/\/www.mongodb.com\/developer\/products\/mongodb\/schema-design-best-practices\/\" target=\"_blank\" rel=\"noreferrer noopener\">Data Modeling Patterns<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-replication-va-sharding\"><strong>Replication v\u00e0 Sharding<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sao ch\u00e9p (replication)<\/strong>: D\u00f9ng replica set \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh s\u1eb5n s\u00e0ng cao (n\u1ebfu m\u1ed9t node h\u1ecfng, node kh\u00e1c v\u1eabn ph\u1ee5c v\u1ee5).<\/li>\n\n\n\n<li><strong>Ph\u00e2n m\u1ea3nh (sharding)<\/strong>: Chia nh\u1ecf d\u1eef li\u1ec7u ra nhi\u1ec1u server \u0111\u1ec3 x\u1eed l\u00fd, gi\u00fap h\u1ec7 th\u1ed1ng m\u1edf r\u1ed9ng ngang khi d\u1eef li\u1ec7u qu\u00e1 l\u1edbn.<\/li>\n<\/ul>\n\n\n\n<p>T\u00e0i li\u1ec7u: <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/replication\/\" target=\"_blank\" rel=\"noreferrer noopener\">Replication Docs<\/a> v\u00e0 <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/sharding\/\" target=\"_blank\" rel=\"noreferrer noopener\">Sharding Docs<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-b\u1ea3o-m\u1eadt-security\"><strong>B\u1ea3o m\u1eadt (Security)<\/strong><\/h3>\n\n\n\n<p>\u200b\u200bMongoDB cung c\u1ea5p c\u00e1c t\u00ednh n\u0103ng b\u1ea3o m\u1eadt nh\u01b0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>X\u00e1c th\u1ef1c (authentication) \u0111\u1ea3m b\u1ea3o ch\u1ec9 ng\u01b0\u1eddi d\u00f9ng h\u1ee3p l\u1ec7 m\u1edbi truy c\u1eadp.<br>Ph\u00e2n quy\u1ec1n d\u1ef1a tr\u00ean vai tr\u00f2 (role-based access control).<\/li>\n\n\n\n<li>M\u00e3 h\u00f3a d\u1eef li\u1ec7u (encryption) khi l\u01b0u tr\u1eef v\u00e0 khi truy\u1ec1n t\u1ea3i.<\/li>\n<\/ul>\n\n\n\n<p>T\u00e0i li\u1ec7u: <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/security\/\" target=\"_blank\" rel=\"noreferrer noopener\">Security Docs<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-hi\u1ec7u-nang-va-giam-sat-performance-amp-monitoring\"><strong>Hi\u1ec7u n\u0103ng v\u00e0 gi\u00e1m s\u00e1t (Performance &amp; Monitoring)<\/strong><\/h3>\n\n\n\n<p>Ta c\u00f3 th\u1ec3 d\u00f9ng l\u1ec7nh explain() \u0111\u1ec3 ph\u00e2n t\u00edch v\u00e0 t\u1ed1i \u01b0u c\u00e1c c\u00e2u l\u1ec7nh truy v\u1ea5n. Ngo\u00e0i ra, MongoDB c\u00f3 c\u00f4ng c\u1ee5 nh\u01b0 Atlas Performance Advisor ho\u1eb7c Ops Manager \u0111\u1ec3 gi\u00e1m s\u00e1t t\u00e0i nguy\u00ean, gi\u00fap ph\u00e1t hi\u1ec7n s\u1edbm c\u00e1c v\u1ea5n \u0111\u1ec1 v\u1ec1 CPU, RAM ho\u1eb7c query ch\u1eadm.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-tai-li\u1ec7u-va-ngu\u1ed3n-h\u1ecdc-mongodb\"><strong>T\u00e0i li\u1ec7u v\u00e0 ngu\u1ed3n h\u1ecdc MongoDB<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB Manual<\/a>: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft t\u1eeb c\u00e0i \u0111\u1eb7t, c\u00e1c l\u1ec7nh c\u01a1 b\u1ea3n \u0111\u1ebfn t\u00ednh n\u0103ng n\u00e2ng cao.<\/li>\n\n\n\n<li><a href=\"https:\/\/learn.mongodb.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB University<\/a>: C\u00e1c kh\u00f3a h\u1ecdc mi\u1ec5n ph\u00ed do ch\u00ednh MongoDB ph\u00e1t tri\u1ec3n, t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao k\u00e8m ch\u1ee9ng ch\u1ec9.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB Developer Hub<\/a>: t\u1eadp trung c\u00e1c b\u00e0i vi\u1ebft, tutorial, video v\u00e0 h\u01b0\u1edbng d\u1eabn th\u1ef1c ti\u1ec5n.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/community\/forums\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB Community Forum<\/a>: Di\u1ec5n \u0111\u00e0n ch\u00ednh th\u1ee9c \u0111\u1ec3 \u0111\u1eb7t c\u00e2u h\u1ecfi, th\u1ea3o lu\u1eadn v\u1edbi chuy\u00ean gia v\u00e0 c\u00e1c developer kh\u00e1c.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-mongodb-tutorial-b\u01b0\u1edbc-5-tim-hi\u1ec3u-cach-x\u1eed-ly-l\u1ed7i-th\u01b0\u1eddng-g\u1eb7p-trong-mongodb\"><span class=\"ez-toc-section\" id=\"MongoDB_tutorial_buoc_5_Tim_hieu_cach_xu_ly_loi_thuong_gap_trong_MongoDB\"><\/span><strong>MongoDB tutorial b\u01b0\u1edbc 5: T\u00ecm hi\u1ec3u c\u00e1ch x\u1eed l\u00fd l\u1ed7i th\u01b0\u1eddng g\u1eb7p trong MongoDB<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>D\u00f9 MongoDB r\u1ea5t th\u00e2n thi\u1ec7n v\u1edbi ng\u01b0\u1eddi m\u1edbi, nh\u01b0ng trong qu\u00e1 tr\u00ecnh l\u00e0m vi\u1ec7c, b\u1ea1n c\u00f3 th\u1ec3 g\u1eb7p m\u1ed9t s\u1ed1 l\u1ed7i ph\u1ed5 bi\u1ebfn. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 c\u00e1ch nh\u1eadn di\u1ec7n v\u00e0 kh\u1eafc ph\u1ee5c ch\u00fang m\u1ed9t c\u00e1ch nhanh ch\u00f3ng:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Kh\u00f4ng kh\u1edfi \u0111\u1ed9ng \u0111\u01b0\u1ee3c MongoDB<\/strong><\/li>\n<\/ol>\n\n\n\n<p>M\u1ed9t trong nh\u1eefng v\u1ea5n \u0111\u1ec1 ph\u1ed5 bi\u1ebfn nh\u1ea5t l\u00e0 d\u1ecbch v\u1ee5 MongoDB kh\u00f4ng kh\u1edfi \u0111\u1ed9ng \u0111\u01b0\u1ee3c. Nguy\u00ean nh\u00e2n th\u01b0\u1eddng do th\u01b0 m\u1ee5c d\u1eef li\u1ec7u m\u1eb7c \u0111\u1ecbnh (<code>C:\\data\\db<\/code> tr\u00ean Windows ho\u1eb7c <code>\/data\/db<\/code> tr\u00ean Linux\/Mac) ch\u01b0a t\u1ed3n t\u1ea1i ho\u1eb7c ng\u01b0\u1eddi d\u00f9ng kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ecdc\/ghi.&nbsp;<\/p>\n\n\n\n<p>Gi\u1ea3i ph\u00e1p: T\u1ea1o th\u1ee7 c\u00f4ng th\u01b0 m\u1ee5c d\u1eef li\u1ec7u v\u00e0 \u0111\u1ea3m b\u1ea3o c\u1ea5p quy\u1ec1n \u0111\u1ea7y \u0111\u1ee7 cho t\u00e0i kho\u1ea3n ch\u1ea1y MongoDB.<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Kh\u00f4ng k\u1ebft n\u1ed1i \u0111\u01b0\u1ee3c t\u1edbi MongoDB<\/strong><\/li>\n<\/ol>\n\n\n\n<p>N\u1ebfu b\u1ea1n th\u1ea5y l\u1ed7i khi k\u1ebft n\u1ed1i (v\u00ed d\u1ee5: <code>connection refused<\/code>), h\u00e3y ki\u1ec3m tra l\u1ea1i \u0111\u1ecba ch\u1ec9 host v\u00e0 c\u1ed5ng (m\u1eb7c \u0111\u1ecbnh l\u00e0 <code>27017<\/code>). Ngo\u00e0i ra, c\u0169ng c\u1ea7n ph\u1ea3i \u0111\u1ea3m b\u1ea3o MongoDB service \u0111ang ch\u1ea1y v\u00e0 \u0111\u1ea3m b\u1ea3o b\u1ea1n nh\u1eadp \u0111\u00fang t\u00ean ng\u01b0\u1eddi d\u00f9ng v\u00e0 m\u1eadt kh\u1ea9u trong tr\u01b0\u1eddng h\u1ee3p c\u1ea7n x\u00e1c th\u1ef1c.<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>L\u1ed7i c\u00fa ph\u00e1p ho\u1eb7c l\u1ec7nh kh\u00f4ng h\u1ee3p l\u1ec7 trong Shell<\/strong><\/li>\n<\/ol>\n\n\n\n<p>M\u1ed9t s\u1ed1 l\u1ed7i th\u01b0\u1eddng g\u1eb7p l\u00e0 sai c\u00fa ph\u00e1p nh\u01b0 qu\u00ean d\u1ea5u ngo\u1eb7c nh\u1ecdn <code>{}<\/code> ho\u1eb7c d\u1ea5u nh\u00e1y <code>\"<\/code>. Khi g\u1eb7p l\u1ed7i n\u00e0y, h\u00e3y \u0111\u1ecdc k\u1ef9 th\u00f4ng b\u00e1o l\u1ed7i c\u1ee7a MongoDB Shell v\u00ec n\u00f3 th\u01b0\u1eddng ch\u1ec9 r\u00f5 v\u1ecb tr\u00ed sai c\u00fa ph\u00e1p.<\/p>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>D\u1eef li\u1ec7u kh\u00f4ng \u0111\u01b0\u1ee3c l\u01b0u l\u1ea1i<\/strong>: <\/li>\n<\/ol>\n\n\n\n<p>Tr\u01b0\u1eddng h\u1ee3p d\u1eef li\u1ec7u bi\u1ebfn m\u1ea5t sau khi kh\u1edfi \u0111\u1ed9ng l\u1ea1i MongoDB c\u00f3 th\u1ec3 do b\u1ea1n \u0111ang ch\u1ea1y trong m\u00f4i tr\u01b0\u1eddng Docker m\u00e0 kh\u00f4ng c\u1ea5u h\u00ecnh volume (\u1ed5 \u0111\u0129a l\u01b0u tr\u1eef).&nbsp;<\/p>\n\n\n\n<p>\u0110\u1ec3 kh\u1eafc ph\u1ee5c, h\u00e3y g\u1eafn th\u00eam volume khi t\u1ea1o container b\u1eb1ng tham s\u1ed1 -v, v\u00ed d\u1ee5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d -p 27017:27017 -v mongodb-data:\/data\/db mongo<\/code><\/pre>\n\n\n\n<p>L\u00fac n\u00e0y, d\u1eef li\u1ec7u s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef b\u1ec1n v\u1eefng v\u00e0 kh\u00f4ng b\u1ecb m\u1ea5t khi container d\u1eebng.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cau-h\u1ecfi-th\u01b0\u1eddng-g\u1eb7p-v\u1ec1-mongodb-tutorial\"><span class=\"ez-toc-section\" id=\"Cau_hoi_thuong_gap_ve_MongoDB_tutorial\"><\/span><strong>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 MongoDB tutorial<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-mongodb-co-d\u1ec5-h\u1ecdc-khong\"><strong>MongoDB c\u00f3 d\u1ec5 h\u1ecdc kh\u00f4ng?<\/strong><\/h3>\n\n\n\n<p>MongoDB kh\u00e1 d\u1ec5 ti\u1ebfp c\u1eadn, \u0111\u1eb7c bi\u1ec7t v\u1edbi nh\u1eefng ai \u0111\u00e3 quen v\u1edbi l\u1eadp tr\u00ecnh web ho\u1eb7c c\u00e1c h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u kh\u00e1c. C\u00fa ph\u00e1p thao t\u00e1c (CRUD &#8211; t\u1ea1o, \u0111\u1ecdc, c\u1eadp nh\u1eadt, x\u00f3a) tr\u1ef1c quan, d\u1eef li\u1ec7u l\u01b0u d\u01b0\u1edbi d\u1ea1ng document (t\u00e0i li\u1ec7u JSON) n\u00ean r\u1ea5t g\u1ea7n g\u0169i v\u1edbi l\u1eadp tr\u00ecnh vi\u00ean.<\/p>\n\n\n\n<p>Tuy nhi\u00ean, \u0111\u1ec3 n\u1eafm v\u1eefng c\u00e1c t\u00ednh n\u0103ng n\u00e2ng cao nh\u01b0 sharding (ph\u00e2n m\u1ea3nh d\u1eef li\u1ec7u), replication (sao l\u01b0u nhi\u1ec1u b\u1ea3n) hay t\u1ed1i \u01b0u hi\u1ec7u n\u0103ng th\u00ec b\u1ea1n c\u1ea7n th\u1eddi gian \u0111\u1ec3 th\u1ef1c h\u00e0nh.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-mongodb-co-mi\u1ec5n-phi-ko\"><strong>MongoDB c\u00f3 mi\u1ec5n ph\u00ed ko?<\/strong><\/h3>\n\n\n\n<p>MongoDB c\u00f3 b\u1ea3n Community Server ho\u00e0n to\u00e0n mi\u1ec5n ph\u00ed, ph\u00f9 h\u1ee3p cho h\u1ecdc t\u1eadp, th\u1eed nghi\u1ec7m v\u00e0 ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng nh\u1ecf. Ngo\u00e0i ra, MongoDB c\u0169ng cung c\u1ea5p MongoDB Atlas Free Tier (b\u1ea3n mi\u1ec5n ph\u00ed tr\u00ean cloud) cho ph\u00e9p t\u1ea1o cluster v\u00e0 th\u1eed nghi\u1ec7m tr\u1ef1c ti\u1ebfp m\u00e0 kh\u00f4ng c\u1ea7n t\u1ef1 c\u00e0i \u0111\u1eb7t.<\/p>\n\n\n\n<p>N\u1ebfu d\u00f9ng trong m\u00f4i tr\u01b0\u1eddng doanh nghi\u1ec7p ho\u1eb7c c\u1ea7n h\u1ed7 tr\u1ee3 n\u00e2ng cao, b\u1ea1n c\u00f3 th\u1ec3 c\u00e2n nh\u1eafc b\u1ea3n Enterprise (c\u00f3 ph\u00ed).<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>\u0110\u1ecdc chi ti\u1ebft: <strong><a href=\"https:\/\/itviec.com\/blog\/huong-dan-mongodb-download\/\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB download: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft cho Windows v\u00e0 MacOS<\/a><\/strong><\/em><\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-m\u1ea5t-bao-lau-d\u1ec3-h\u1ecdc-mongodb\"><strong>M\u1ea5t bao l\u00e2u \u0111\u1ec3 h\u1ecdc MongoDB?<\/strong><\/h3>\n\n\n\n<p>Th\u1eddi gian \u0111\u1ec3 h\u1ecdc MongoDB ph\u1ee5 thu\u1ed9c v\u00e0o m\u1ee5c ti\u00eau v\u00e0 m\u1ee9c \u0111\u1ed9 b\u1ea1n mu\u1ed1n \u0111\u1ea1t \u0111\u01b0\u1ee3c. V\u00ed d\u1ee5, b\u1ea1n c\u00f3 th\u1ec3 l\u00e0m quen c\u01a1 b\u1ea3n v\u1edbi MongoDB ch\u1ec9 trong v\u00e0i ph\u00fat v\u1edbi c\u00e1c t\u00e0i li\u1ec7u, tutorial c\u00f3 s\u1eb5n. C\u00f2n c\u00e1c kh\u00f3a h\u1ecdc chuy\u00ean s\u00e2u, n\u00e2ng cao v\u1ec1 MongoDB c\u00f3 th\u1ec3 k\u00e9o d\u00e0i t\u1eeb 1-2 th\u00e1ng.<\/p>\n\n\n\n<p>N\u1ebfu b\u1ea1n \u0111ang d\u00f9ng MongoDB trong d\u1ef1 \u00e1n th\u1ef1c t\u1ebf, h\u00e3y th\u1ef1c h\u00e0nh th\u1eadt nhi\u1ec1u \u0111\u1ec3 h\u1ecdc nhanh h\u01a1n.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-t\u1ed5ng-k\u1ebft\"><span class=\"ez-toc-section\" id=\"Tong_ket\"><\/span><strong>T\u1ed5ng k\u1ebft<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>MongoDB l\u00e0 m\u1ed9t l\u1ef1a ch\u1ecdn tuy\u1ec7t v\u1eddi cho c\u1ea3 ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u v\u00e0 c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean mu\u1ed1n ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng quy m\u00f4 l\u1edbn. H\u1ecdc MongoDB kh\u00f4ng ch\u1ec9 l\u00e0 h\u1ecdc m\u1ed9t c\u00f4ng c\u1ee5 c\u01a1 s\u1edf d\u1eef li\u1ec7u, m\u00e0 c\u00f2n l\u00e0 m\u1edf ra c\u00e1nh c\u1eeda \u0111\u1ec3 x\u00e2y d\u1ef1ng nh\u1eefng \u1ee9ng d\u1ee5ng hi\u1ec7n \u0111\u1ea1i, linh ho\u1ea1t v\u00e0 hi\u1ec7u qu\u1ea3.&nbsp;<\/p>\n\n\n\n<p>Vi\u1ec7c h\u1ecdc MongoDB n\u00ean \u0111i t\u1eeb g\u1ed1c r\u1ec5: hi\u1ec3u c\u1ea5u tr\u00fac document, th\u1ef1c h\u00e0nh CRUD, sau \u0111\u00f3 t\u1eebng b\u01b0\u1edbc chinh ph\u1ee5c c\u00e1c t\u00ednh n\u0103ng n\u00e2ng cao nh\u01b0 aggregation, indexing, data modeling, replication, v\u00e0 security. ITviec hy v\u1ecdng b\u00e0i vi\u1ebft tr\u00ean \u0111\u00e3 cung c\u1ea5p cho b\u1ea1n nh\u1eefng th\u00f4ng tin b\u1ed5 \u00edch v\u00e0 l\u1ed9 tr\u00ecnh chinh ph\u1ee5c MongoDB ph\u00f9 h\u1ee3p.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MongoDB l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 m\u1ea1nh m\u1ebd, nh\u01b0ng \u0111\u1ec3 khai th\u00e1c h\u1ebft s\u1ee9c m\u1ea1nh c\u1ee7a n\u00f3 th\u00ec b\u1ea1n c\u1ea7n nhi\u1ec1u h\u01a1n l\u00e0 \u201ch\u1ecdc thu\u1ed9c c\u00e2u l\u1ec7nh\u201d. \u0110\u1ec3 h\u1ecdc MongoDB hi\u1ec7u qu\u1ea3, b\u1ea1n c\u1ea7n t\u01b0 duy theo h\u01b0\u1edbng d\u1eef li\u1ec7u phi c\u1ea5u tr\u00fac v\u00e0 bi\u1ebft c\u00e1ch x\u00e2y d\u1ef1ng l\u1ed9 tr\u00ecnh h\u1ecdc t\u1eadp h\u1ee3p l\u00fd \u0111\u1ec3 kh\u00f4ng [&hellip;]<\/p>\n","protected":false},"author":209,"featured_media":91696,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109],"tags":[],"class_list":["post-91549","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>MongoDB tutorial c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn c\u00e1c b\u01b0\u1edbc h\u1ecdc MongoDB to\u00e0n di\u1ec7n - ITviec Blog<\/title>\n<meta name=\"description\" content=\"Chi ti\u1ebft MongoDB tutorial c\u01a1 b\u1ea3n cho ng\u01b0\u1eddi m\u1edbi: c\u00e0i \u0111\u1eb7t, thao t\u00e1c CRUD, truy v\u1ea5n,.. k\u00e8m l\u1ed9 tr\u00ecnh h\u1ecdc c\u00e1c ch\u1ee7 \u0111\u1ec1 n\u00e2ng cao.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MongoDB tutorial c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn c\u00e1c b\u01b0\u1edbc h\u1ecdc MongoDB to\u00e0n di\u1ec7n\" \/>\n<meta property=\"og:description\" content=\"MongoDB l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 m\u1ea1nh m\u1ebd, nh\u01b0ng \u0111\u1ec3 khai th\u00e1c h\u1ebft s\u1ee9c m\u1ea1nh c\u1ee7a n\u00f3 th\u00ec b\u1ea1n c\u1ea7n nhi\u1ec1u h\u01a1n l\u00e0 \u201ch\u1ecdc thu\u1ed9c c\u00e2u l\u1ec7nh\u201d. \u0110\u1ec3 h\u1ecdc MongoDB hi\u1ec7u qu\u1ea3, b\u1ea1n c\u1ea7n t\u01b0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-27T15:04:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-27T15:05:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/mongodb-tutorial-scaled.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1347\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"M\u1ef9 Duy\u00ean\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"M\u1ef9 Duy\u00ean\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"MongoDB tutorial c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn c\u00e1c b\u01b0\u1edbc h\u1ecdc MongoDB to\u00e0n di\u1ec7n - ITviec Blog","description":"Chi ti\u1ebft MongoDB tutorial c\u01a1 b\u1ea3n cho ng\u01b0\u1eddi m\u1edbi: c\u00e0i \u0111\u1eb7t, thao t\u00e1c CRUD, truy v\u1ea5n,.. k\u00e8m l\u1ed9 tr\u00ecnh h\u1ecdc c\u00e1c ch\u1ee7 \u0111\u1ec1 n\u00e2ng cao.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/","og_locale":"vi_VN","og_type":"article","og_title":"MongoDB tutorial c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn c\u00e1c b\u01b0\u1edbc h\u1ecdc MongoDB to\u00e0n di\u1ec7n","og_description":"MongoDB l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 m\u1ea1nh m\u1ebd, nh\u01b0ng \u0111\u1ec3 khai th\u00e1c h\u1ebft s\u1ee9c m\u1ea1nh c\u1ee7a n\u00f3 th\u00ec b\u1ea1n c\u1ea7n nhi\u1ec1u h\u01a1n l\u00e0 \u201ch\u1ecdc thu\u1ed9c c\u00e2u l\u1ec7nh\u201d. \u0110\u1ec3 h\u1ecdc MongoDB hi\u1ec7u qu\u1ea3, b\u1ea1n c\u1ea7n t\u01b0","og_url":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-09-27T15:04:32+00:00","article_modified_time":"2025-09-27T15:05:08+00:00","og_image":[{"width":2560,"height":1347,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/mongodb-tutorial-scaled.png","type":"image\/png"}],"author":"M\u1ef9 Duy\u00ean","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"M\u1ef9 Duy\u00ean","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"14 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/"},"author":{"name":"M\u1ef9 Duy\u00ean","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7"},"headline":"MongoDB tutorial c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn c\u00e1c b\u01b0\u1edbc h\u1ecdc MongoDB to\u00e0n di\u1ec7n","datePublished":"2025-09-27T15:04:32+00:00","dateModified":"2025-09-27T15:05:08+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/"},"wordCount":3796,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/mongodb-tutorial-scaled.png","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/","url":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/","name":"MongoDB tutorial c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn c\u00e1c b\u01b0\u1edbc h\u1ecdc MongoDB to\u00e0n di\u1ec7n - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/mongodb-tutorial-scaled.png","datePublished":"2025-09-27T15:04:32+00:00","dateModified":"2025-09-27T15:05:08+00:00","description":"Chi ti\u1ebft MongoDB tutorial c\u01a1 b\u1ea3n cho ng\u01b0\u1eddi m\u1edbi: c\u00e0i \u0111\u1eb7t, thao t\u00e1c CRUD, truy v\u1ea5n,.. k\u00e8m l\u1ed9 tr\u00ecnh h\u1ecdc c\u00e1c ch\u1ee7 \u0111\u1ec1 n\u00e2ng cao.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/mongodb-tutorial-scaled.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/mongodb-tutorial-scaled.png","width":800,"height":421,"caption":"MongoDB tutorial - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/lo-trinh-hoc-tap-mongodb-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"MongoDB tutorial c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn c\u00e1c b\u01b0\u1edbc h\u1ecdc MongoDB to\u00e0n di\u1ec7n"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7","name":"M\u1ef9 Duy\u00ean","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","caption":"M\u1ef9 Duy\u00ean"},"url":"https:\/\/itviec.com\/blog\/author\/my-duyen\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/91549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/209"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=91549"}],"version-history":[{"count":3,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/91549\/revisions"}],"predecessor-version":[{"id":91698,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/91549\/revisions\/91698"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/91696"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=91549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=91549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=91549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}