{"id":47017,"date":"2025-07-30T05:32:05","date_gmt":"2025-07-29T21:32:05","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/47017.html"},"modified":"2025-07-30T05:32:05","modified_gmt":"2025-07-29T21:32:05","slug":"c%e5%90%8e%e7%ab%af%e7%bc%96%e7%a8%8b-%e6%9e%84%e5%bb%ba%e9%ab%98%e6%80%a7%e8%83%bd%e5%90%8e%e7%ab%af%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93%e3%80%81api-%e4%b8%8e-web-%e6%9c%8d%e5%8a%a1%e5%99%a8-5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/47017.html","title":{"rendered":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c"},"content":{"rendered":"<h2 id=\"aid_240\" style=\"text-align:justify\"><span style=\"color:#000000\">\u6570\u636e\u5e93\u5728\u540e\u7aef\u5f00\u53d1\u4e2d\u7684\u89d2\u8272<\/span><\/h2>\n<p><span style=\"color:#000000\">\u5728\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u9886\u57df&#xff0c;\u6570\u636e\u5e93\u5728\u6570\u636e\u7684\u6301\u4e45\u5316\u5b58\u50a8\u3001\u68c0\u7d22\u548c\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u626e\u6f14\u7740\u81f3\u5173\u91cd\u8981\u7684\u89d2\u8272\u3002\u00a0\u56e0\u6b64&#xff0c;\u6570\u636e\u5e93\u4e3a\u5e94\u7528\u7a0b\u5e8f\u6267\u884c\u7684\u5927\u591a\u6570&#xff08;\u82e5\u975e\u5168\u90e8&#xff09;\u529f\u80fd\u63d0\u4f9b\u4e86\u57fa\u7840\u652f\u6491\u3002\u00a0\u65e0\u8bba\u662f\u7b80\u5355\u8fd8\u662f\u590d\u6742\u7684\u64cd\u4f5c&#xff0c;\u6570\u636e\u5e93\u90fd\u4e0d\u53ef\u6216\u7f3a&#xff1b;\u4f8b\u5982\u6ce8\u518c\u65b0\u7528\u6237\u662f\u7b80\u5355\u4efb\u52a1&#xff0c;\u800c\u5206\u6790\u7528\u6237\u884c\u4e3a\u6a21\u5f0f\u4ee5\u5b9e\u73b0\u4e2a\u6027\u5316\u63a8\u8350\u7cfb\u7edf\u5219\u662f\u590d\u6742\u64cd\u4f5c\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u5f00\u53d1\u7f51\u7ad9\u6216\u5e94\u7528\u7a0b\u5e8f\u7684\u540e\u7aef\u65f6&#xff0c;\u6570\u636e\u5e93\u901a\u5e38\u662f\u67b6\u6784\u4e2d\u6700\u91cd\u8981\u7684\u7ec4\u6210\u90e8\u5206\u3002\u00a0\u8fd9\u91cc\u662f\u4e1a\u52a1\u6570\u636e\u3001\u7528\u6237\u4fe1\u606f\u3001\u5e94\u7528\u7a0b\u5e8f\u72b6\u6001\u7b49\u5185\u5bb9\u88ab\u7ba1\u7406\u548c\u5b58\u50a8\u7684\u5730\u65b9\u3002\u00a0\u540e\u7aef\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u4e0e\u6570\u636e\u5e93\u8fdb\u884c\u4ea4\u4e92&#xff0c;\u4ee5\u6267\u884c\u56db\u9879\u57fa\u672c\u7684 CRUD \u64cd\u4f5c&#xff08;\u521b\u5efa\u3001\u8bfb\u53d6\u3001\u66f4\u65b0\u548c\u5220\u9664&#xff09;\u3002\u00a0\u8fd9\u4e9b\u64cd\u4f5c\u5bf9\u4e8e\u4efb\u4f55\u6570\u636e\u9a71\u52a8\u7684\u5e94\u7528\u7a0b\u5e8f\u90fd\u662f\u5fc5\u9700\u7684\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u521b\u5efa&#xff1a;\u8be5\u64cd\u4f5c\u6d89\u53ca\u5411\u6570\u636e\u5e93\u6dfb\u52a0\u65b0\u6570\u636e\u3002\u00a0\u5305\u62ec\u6ce8\u518c\u65b0\u7528\u6237\u3001\u521b\u5efa\u65b0\u4ea7\u54c1\u6216\u63d2\u5165\u65b0\u535a\u5ba2\u6587\u7ae0\u7b49\u64cd\u4f5c\u3002\u00a0\u8fd9\u4e9b\u64cd\u4f5c\u901a\u5e38\u9700\u8981\u540e\u7aef\u5e94\u7528\u7a0b\u5e8f\u63a5\u6536\u6765\u81ea\u5ba2\u6237\u7aef\u5e94\u7528\u7684\u6570\u636e&#xff0c;\u6267\u884c\u9a8c\u8bc1\u540e\u5411\u6570\u636e\u5e93\u53d1\u51fa INSERT \u547d\u4ee4\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u8bfb\u53d6&#xff1a;\u4ece\u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e\u662f\u6700\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u00a0\u6bcf\u5f53\u7528\u6237\u767b\u5f55\u3001\u641c\u7d22\u4ea7\u54c1\u6216\u6d4f\u89c8\u7f51\u9875\u5e94\u7528\u7684\u4e0d\u540c\u9875\u9762\u65f6&#xff0c;\u540e\u7aef\u90fd\u4f1a\u6267\u884c\u8bfb\u53d6\u64cd\u4f5c\u3002\u00a0\u8fd9\u6d89\u53ca\u5411\u6570\u636e\u5e93\u53d1\u51fa SELECT \u547d\u4ee4&#xff0c;\u901a\u5e38\u9644\u5e26\u7279\u5b9a\u6761\u4ef6\u6765\u7b5b\u9009\u6570\u636e\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u66f4\u65b0&#xff1a;\u66f4\u65b0\u64cd\u4f5c\u4f1a\u4fee\u6539\u6570\u636e\u5e93\u4e2d\u7684\u73b0\u6709\u6570\u636e\u3002\u00a0\u4f8b\u5982\u5f53\u7528\u6237\u66f4\u65b0\u4e2a\u4eba\u8d44\u6599\u3001\u66f4\u6539\u8bbe\u7f6e&#xff0c;\u6216\u7535\u5546\u5e94\u7528\u5728\u8d2d\u4e70\u540e\u66f4\u65b0\u4ea7\u54c1\u5e93\u5b58\u65f6\u3002\u00a0\u8fd9\u6d89\u53ca\u540e\u7aef\u5411\u6570\u636e\u5e93\u53d1\u51fa UPDATE \u547d\u4ee4\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u5220\u9664&#xff1a;\u6700\u540e&#xff0c;\u5220\u9664\u64cd\u4f5c\u4f1a\u4ece\u6570\u636e\u5e93\u4e2d\u79fb\u9664\u73b0\u6709\u6570\u636e\u3002\u00a0\u8fd9\u53ef\u80fd\u53d1\u751f\u5728\u7528\u6237\u6ce8\u9500\u8d26\u6237&#xff0c;\u6216\u7ba1\u7406\u5458\u4ece\u7535\u5546\u5e73\u53f0\u4e0b\u67b6\u505c\u552e\u5546\u54c1\u65f6\u3002\u00a0\u540e\u7aef\u4f1a\u5411\u6570\u636e\u5e93\u53d1\u51fa DELETE \u547d\u4ee4\u6765\u6267\u884c\u6b64\u64cd\u4f5c\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u9664\u4e86\u8fd9\u4e9b\u57fa\u672c\u64cd\u4f5c\u5916&#xff0c;\u6570\u636e\u5e93\u8fd8\u652f\u6301\u66f4\u590d\u6742\u7684\u64cd\u4f5c&#xff0c;\u5982\u805a\u5408&#xff08;\u8ba1\u7b97\u603b\u548c\u3001\u5e73\u5747\u503c\u7b49\u7c7b\u4f3c\u503c&#xff09;\u3001\u591a\u8868\u6570\u636e\u8fde\u63a5\u4ee5\u53ca\u4e8b\u52a1&#xff08;\u5c06\u591a\u4e2a\u64cd\u4f5c\u7ec4\u5408\u6210\u4e00\u4e2a\u5de5\u4f5c\u5355\u5143&#xff09;\u3002\u00a0\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u9700\u6c42\u5e94\u6307\u5bfc\u6570\u636e\u5e93\u7684\u9009\u62e9&#xff0c;\u53ef\u4ee5\u662f\u4f20\u7edf\u7684 SQL \u6570\u636e\u5e93&#xff08;\u5982 MySQL \u6216 PostgreSQL&#xff09;&#xff0c;\u4e5f\u53ef\u4ee5\u662f NoSQL \u6570\u636e\u5e93&#xff08;\u5982 MongoDB \u6216 Cassandra&#xff09;\u3002\u00a0\u4e24\u79cd\u7c7b\u578b\u7684\u6570\u636e\u5e93\u90fd\u4ee5\u5173\u7cfb\u683c\u5f0f\u5b58\u50a8\u6570\u636e\u3002\u00a0\u4e3a\u4e86\u6ee1\u8db3\u5404\u79cd\u9700\u6c42&#xff0c;\u67d0\u4e9b\u5e94\u7528\u7a0b\u5e8f\u751a\u81f3\u53ef\u80fd\u4f7f\u7528\u591a\u79cd\u4e0d\u540c\u7684\u6570\u636e\u5e93\u7c7b\u578b\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6848&#xff0c;\u540e\u7aef\u5f00\u53d1\u4eba\u5458\u90fd\u5fc5\u987b\u624e\u5b9e\u638c\u63e1\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u57fa\u7840\u77e5\u8bc6&#xff0c;\u5305\u62ec\u5982\u4f55\u9ad8\u6548\u8bbe\u8ba1\u6570\u636e\u5e93\u6a21\u5f0f\u3001\u7f16\u5199\u67e5\u8be2\u8bed\u53e5\u4ee5\u53ca\u5904\u7406\u6f5c\u5728\u7684\u9519\u8bef\u548c\u5f02\u5e38\u3002\u00a0\u82e5\u5177\u5907\u8fd9\u4e9b\u6280\u80fd&#xff0c;\u5f00\u53d1\u8005\u5c31\u80fd\u786e\u4fdd\u5e94\u7528\u6570\u636e\u5c42\u7684\u5065\u58ee\u6027\u4e0e\u9ad8\u6548\u6027&#xff0c;\u8fdb\u800c\u4fdd\u969c\u6574\u4e2a\u5e94\u7528\u7684\u6027\u80fd\u4e0e\u53ef\u9760\u6027\u3002<\/span><\/p>\n<h2 id=\"aid_169\" style=\"text-align:justify\"><span style=\"color:#000000\">\u63a2\u7d22 MongoDB<\/span><\/h2>\n<p><span style=\"color:#000000\">MongoDB \u662f\u4e00\u79cd\u6d41\u884c\u7684 NoSQL \u6570\u636e\u5e93&#xff0c;\u5177\u6709\u9ad8\u6027\u80fd\u3001\u9ad8\u53ef\u7528\u6027\u548c\u6613\u4e8e\u6269\u5c55\u7684\u7279\u70b9\u3002\u00a0\u4e0e\u4f20\u7edf\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e0d\u540c&#xff0c;MongoDB \u4ee5\u7075\u6d3b\u7684\u7c7b JSON \u6587\u6863\u683c\u5f0f\u5b58\u50a8\u6570\u636e&#xff0c;\u8fd9\u610f\u5473\u7740\u4e0d\u540c\u6587\u6863\u53ef\u4ee5\u5305\u542b\u4e0d\u540c\u5b57\u6bb5&#xff0c;\u6570\u636e\u7ed3\u6784\u4e5f\u80fd\u968f\u65f6\u95f4\u53d8\u5316\u3002\u00a0\u6b63\u662f\u8fd9\u79cd\u7075\u6d3b\u6027&#xff0c;\u52a0\u4e0a\u5176\u4ed6\u7279\u6027&#xff0c;\u4f7f\u5176\u6210\u4e3a\u8bb8\u591a\u5e94\u7528\u4e2d\u6bd4\u4f20\u7edf\u5173\u7cfb\u578b\u6570\u636e\u5e93\u66f4\u5177\u5438\u5f15\u529b\u7684\u9009\u62e9\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7075\u6d3b\u7684\u6570\u636e\u6a21\u578b<\/span><\/p>\n<p><span style=\"color:#000000\">MongoDB \u76f8\u8f83\u4e8e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7684\u9996\u8981\u4f18\u52bf\u5728\u4e8e\u5176\u7075\u6d3b\u7684\u67b6\u6784\u3002\u00a0\u8fd9\u79cd\u7075\u6d3b\u6027\u4f7f\u5f97\u5e94\u7528\u5f00\u53d1\u66f4\u5feb\u901f&#xff0c;\u56e0\u4e3a\u5f00\u53d1\u8005\u65e0\u9700\u9884\u5148\u5b9a\u4e49\u6570\u636e\u7ed3\u6784&#xff0c;\u6216\u5728\u6dfb\u52a0\u65b0\u5b57\u6bb5\u65f6\u4fee\u6539\u7ed3\u6784\u3002\u00a0\u8fd9\u4e5f\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u5b58\u50a8\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784&#xff0c;\u5982\u5d4c\u5957\u6570\u7ec4\u548c\u6587\u6863&#xff0c;\u8fd9\u5728\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\u5f80\u5f80\u96be\u4ee5\u5b9e\u73b0\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u53ef\u6269\u5c55\u6027<\/span><\/p>\n<p><span style=\"color:#000000\">MongoDB \u7684\u6c34\u5e73\u6269\u5c55\u67b6\u6784\u4f7f\u5176\u66f4\u9002\u5408\u5904\u7406\u4e0d\u65ad\u589e\u957f\u7684\u5927\u578b\u6570\u636e\u96c6\u3002\u00a0\u4e0e SQL \u6570\u636e\u5e93\u5e38\u89c1\u7684\u901a\u8fc7\u589e\u5f3a\u5355\u53f0\u670d\u52a1\u5668\u6027\u80fd\u8fdb\u884c\u7eb5\u5411\u6269\u5c55\u4e0d\u540c&#xff0c;MongoDB \u901a\u8fc7\u5411\u7f51\u7edc\u6dfb\u52a0\u66f4\u591a\u670d\u52a1\u5668\u5b9e\u73b0\u6a2a\u5411\u6269\u5c55\u3002\u00a0\u8fd9\u79cd\u901a\u8fc7\u6dfb\u52a0\u673a\u5668\u5b9e\u73b0\u6269\u5c55\u7684\u80fd\u529b&#xff08;\u79f0\u4e3a\u5206\u7247&#xff09;\u662f MongoDB \u7684\u5f3a\u5927\u7279\u6027&#xff0c;\u4e3a\u5927\u6570\u636e\u6311\u6218\u63d0\u4f9b\u4e86\u6709\u6548\u89e3\u51b3\u65b9\u6848\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u901f\u5ea6<\/span><\/p>\n<p><span style=\"color:#000000\">\u5bf9\u4e8e\u591a\u79cd\u7c7b\u578b\u7684\u64cd\u4f5c&#xff0c;MongoDB \u901a\u5e38\u6bd4\u5173\u7cfb\u578b\u6570\u636e\u5e93\u66f4\u5feb\u3002\u00a0\u8fd9\u79cd\u901f\u5ea6\u4f18\u52bf\u6e90\u4e8e\u5176\u5904\u7406\u5927\u91cf\u975e\u7ed3\u6784\u5316\u6570\u636e\u7684\u80fd\u529b&#xff0c;\u4ee5\u53ca\u7d22\u5f15\u7b49\u80fd\u663e\u8457\u52a0\u5feb\u6570\u636e\u8bbf\u95ee\u901f\u5ea6\u7684\u7279\u6027\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u590d\u5236\u4e0e\u9ad8\u53ef\u7528\u6027<\/span><\/p>\n<p><span style=\"color:#000000\">MongoDB \u901a\u8fc7\u5185\u7f6e\u7684\u590d\u5236\u529f\u80fd\u63d0\u9ad8\u6570\u636e\u53ef\u7528\u6027&#xff0c;\u5728\u4e0d\u540c\u670d\u52a1\u5668\u4e0a\u7ef4\u62a4\u6570\u636e\u7684\u591a\u4e2a\u526f\u672c\u3002\u00a0\u81ea\u52a8\u6545\u969c\u8f6c\u79fb\u610f\u5473\u7740\u5982\u679c\u4e3b\u670d\u52a1\u5668\u5b95\u673a&#xff0c;\u65b0\u7684\u4e3b\u670d\u52a1\u5668\u5c06\u81ea\u52a8\u542f\u52a8\u5e76\u8fd0\u884c\u3002\u00a0\u6b64\u7279\u6027\u6709\u52a9\u4e8e\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u6301\u7eed\u8fd0\u884c&#xff0c;\u6570\u636e\u59cb\u7ec8\u53ef\u7528\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4e30\u5bcc\u7684\u67e5\u8be2\u8bed\u8a00<\/span><\/p>\n<p><span style=\"color:#000000\">MongoDB \u652f\u6301\u4e30\u5bcc\u4e14\u5bcc\u6709\u8868\u73b0\u529b\u7684\u9762\u5411\u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00\u3002\u00a0\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u5355\u952e\u67e5\u8be2\u3001\u8303\u56f4\u67e5\u8be2\u3001\u6587\u672c\u641c\u7d22\u3001\u56fe\u5904\u7406\u4ee5\u53ca\u901a\u8fc7\u5b9e\u65f6\u805a\u5408\u5b9e\u73b0\u7684\u5730\u7406\u7a7a\u95f4\u67e5\u8be2\u7b49\u591a\u79cd\u65b9\u5f0f&#xff0c;\u6784\u5efa\u80fd\u591f\u7075\u6d3b\u67e5\u8be2\u5206\u6790\u6570\u636e\u7684\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u63d0\u4f9b\u5f3a\u5927\u7684\u6570\u636e\u8bbf\u95ee\u4e0e\u5206\u6790\u80fd\u529b\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5fc5\u987b\u7262\u8bb0\u7684\u662f&#xff0c;\u5c3d\u7ba1 MongoDB \u5177\u6709\u591a\u79cd\u4f18\u52bf&#xff0c;\u4f46\u5b83\u5e76\u975e\u653e\u4e4b\u56db\u6d77\u800c\u7686\u51c6\u7684\u89e3\u51b3\u65b9\u6848\u3002\u00a0\u5b83\u5e76\u4e0d\u9002\u5408\u5728\u6240\u6709\u60c5\u51b5\u4e0b\u90fd\u4f5c\u4e3a\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7684\u66ff\u4ee3\u54c1\u4f7f\u7528\u3002\u00a0\u5bf9\u4e8e\u67d0\u4e9b\u4f7f\u7528\u573a\u666f\u548c\u5e94\u7528\u800c\u8a00&#xff0c;\u5173\u7cfb\u578b\u6570\u636e\u5e93\u63d0\u4f9b\u7684\u66f4\u7ed3\u6784\u5316\u65b9\u6cd5\u53ef\u80fd\u66f4\u4e3a\u6709\u5229\u3002<\/span><\/p>\n<h2 id=\"aid_295\" style=\"text-align:justify\"><span style=\"color:#000000\">\u5b89\u88c5\u548c\u914d\u7f6e MongoDB<\/span><\/h2>\n<p><span style=\"color:#000000\">\u8981\u5c06 MongoDB \u96c6\u6210\u5230 C&#043;&#043;\u5f00\u53d1\u73af\u5883\u4e2d&#xff0c;\u9996\u5148\u9700\u8981\u5728\u7cfb\u7edf\u4e0a\u5b89\u88c5 MongoDB\u3002\u00a0\u4ece MongoDB \u5b98\u7f51\u4e0b\u8f7d MongoDB \u793e\u533a\u7248\u670d\u52a1\u5668&#xff0c;\u5e76\u6309\u7167\u5b89\u88c5\u8bf4\u660e\u8fdb\u884c\u64cd\u4f5c\u3002\u00a0\u63a5\u7740\u5b89\u88c5 MongoDB C&#043;&#043;\u9a71\u52a8\u7a0b\u5e8f&#xff0c;\u8be5\u9a71\u52a8\u80fd\u8ba9\u60a8\u7684 C&#043;&#043;\u5e94\u7528\u7a0b\u5e8f\u4e0e MongoDB \u4ea4\u4e92\u3002\u00a0\u60a8\u53ef\u4ee5\u4f7f\u7528 Homebrew \u7b49\u5305\u7ba1\u7406\u5668\u5b89\u88c5&#xff0c;\u6216\u901a\u8fc7 GitHub \u4ece\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5\u3002\u00a0\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u5728 C&#043;&#043;\u4ee3\u7801\u4e2d\u5305\u542b\u5fc5\u8981\u7684\u5934\u6587\u4ef6\u3002\u00a0\u73b0\u5728&#xff0c;\u60a8\u5c31\u53ef\u4ee5\u4f7f\u7528 MongoDB URI \u5efa\u7acb\u4e0e MongoDB \u670d\u52a1\u5668\u7684\u8fde\u63a5&#xff0c;\u5e76\u5f00\u59cb\u901a\u8fc7 C&#043;&#043;\u5e94\u7528\u7a0b\u5e8f\u5728 MongoDB \u6570\u636e\u5e93\u4e2d\u521b\u5efa\u3001\u8bfb\u53d6\u3001\u66f4\u65b0\u548c\u5220\u9664\u6570\u636e\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4ee5\u4e0b\u662f\u5206\u6b65\u64cd\u4f5c\u6307\u5357&#xff1a;<\/span><\/p>\n<p><span style=\"color:#000000\">\u5b89\u88c5 MongoDB<\/span><\/p>\n<p><span style=\"color:#000000\">\u6839\u636e\u60a8\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf&#xff0c;\u5b89\u88c5 MongoDB \u7684\u8fc7\u7a0b\u53ef\u80fd\u6709\u6240\u4e0d\u540c\u3002\u00a0\u60a8\u53ef\u4ee5\u5728 MongoDB \u6587\u6863\u4e2d\u627e\u5230\u9488\u5bf9\u60a8\u7279\u5b9a\u7cfb\u7edf\u7684\u8be6\u7ec6\u8bf4\u660e\u3002\u00a0\u4ee5\u4e0b\u662f\u5728\u57fa\u4e8e Unix \u7684\u7cfb\u7edf\u4e0a\u7684\u5b89\u88c5\u6b65\u9aa4&#xff1a;<\/span><\/p>\n<p><span style=\"color:#000000\">\u66f4\u65b0\u7cfb\u7edf\u7684\u8f6f\u4ef6\u5305\u6570\u636e\u5e93\u3002<\/span><\/p>\n<p>sudo apt-get update<\/p>\n<p><span style=\"color:#000000\">\u5b89\u88c5 MongoDB\u3002<\/span><\/p>\n<p>sudo apt-get install -y mongodb<\/p>\n<p><span style=\"color:#000000\">\u4e3a\u786e\u4fdd MongoDB \u80fd\u968f\u670d\u52a1\u5668\u81ea\u52a8\u542f\u52a8\u548c\u91cd\u542f&#xff0c;\u53ef\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/span><\/p>\n<p>sudo systemctl enable mongodb<\/p>\n<p><span style=\"color:#000000\">\u5b89\u88c5 MongoDB C&#043;&#043;\u9a71\u52a8<\/span><\/p>\n<p><span style=\"color:#000000\">MongoDB C&#043;&#043;\u9a71\u52a8\u7a0b\u5e8f\u4f7f\u60a8\u7684 C&#043;&#043;\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u4e0e MongoDB \u8fdb\u884c\u4ea4\u4e92\u3002BSON \u662f\u7c7b JSON \u6587\u6863\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f&#xff0c;\u5728\u5b58\u50a8\u548c\u8bbf\u95ee\u6570\u636e\u65f6\u4f7f\u7528\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4&#xff1a;<\/span><\/p>\n<p><span style=\"color:#000000\">\u9996\u5148&#xff0c;\u5b89\u88c5\u6784\u5efa\u9a71\u52a8\u7a0b\u5e8f\u6240\u9700\u7684\u8f6f\u4ef6\u5305&#xff1a;<\/span><\/p>\n<p>sudo apt-get install build-essential libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev<\/p>\n<p><span style=\"color:#000000\">\u63a5\u4e0b\u6765&#xff0c;\u514b\u9686 MongoDB C&#043;&#043;\u9a71\u52a8\u4ed3\u5e93&#xff1a;<\/span><\/p>\n<p>git clone https:\/\/github.com\/mongodb\/mongo-cxx-driver.git<\/p>\n<p><span style=\"color:#000000\">\u8fdb\u5165\u76ee\u5f55\u5e76\u7f16\u8bd1\u9a71\u52a8&#xff1a;<\/span><\/p>\n<p>cd mongo-cxx-driver\/build<br \/>\ncmake -DCMAKE_BUILD_TYPE&#061;Release -DCMAKE_INSTALL_PREFIX&#061;\/usr\/local ..<br \/>\nmake EP_mnmlstc_core<br \/>\nsudo make install<\/p>\n<p><span style=\"color:#000000\">\u6700\u540e&#xff0c;\u60a8\u5c31\u53ef\u4ee5\u5728 C&#043;&#043;\u7a0b\u5e8f\u4e2d\u4f7f\u7528 MongoDB \u4e86\u3002<\/span><\/p>\n<h2 id=\"aid_42\" style=\"text-align:justify\"><span style=\"color:#000000\">\u8fde\u63a5 MongoDB \u7684\u793a\u4f8b\u7a0b\u5e8f<\/span><\/h2>\n<p><span style=\"color:#000000\">\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 C&#043;&#043;\u7a0b\u5e8f&#xff0c;\u7528\u4e8e\u8fde\u63a5\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u8fd0\u884c\u7684 MongoDB \u5b9e\u4f8b&#xff1a;<\/span><\/p>\n<p>#include &lt;bsoncxx\/json.hpp&gt;<br \/>\n#include &lt;mongocxx\/client.hpp&gt;<br \/>\n#include &lt;mongocxx\/stdx.hpp&gt;<br \/>\n#include &lt;mongocxx\/uri.hpp&gt;<br \/>\nusing bsoncxx::builder::stream::close_document;<br \/>\nusing bsoncxx::builder::stream::open_document;<br \/>\nusing bsoncxx::builder::stream::document;<br \/>\nint main(int, char**) {<br \/>\n  mongocxx::instance inst{};<br \/>\n  mongocxx::client conn{mongocxx::uri{}};<br \/>\n   auto collection &#061; conn[&#034;testdb&#034;][&#034;testcollection&#034;];<br \/>\n  document builder{};<br \/>\n   builder &lt;&lt; &#034;name&#034; &lt;&lt; &#034;MongoDB&#034; &lt;&lt; &#034;type&#034; &lt;&lt; &#034;database&#034; &lt;&lt; &#034;count&#034; &lt;&lt; 1<br \/>\n          &lt;&lt; &#034;versions&#034; &lt;&lt; bsoncxx::builder::stream::open_array<br \/>\n          &lt;&lt; &#034;v3.2&#034; &lt;&lt; &#034;v3.0&#034; &lt;&lt; &#034;v2.6&#034;<br \/>\n          &lt;&lt; close_array<br \/>\n          &lt;&lt; &#034;info&#034; &lt;&lt; open_document &lt;&lt; &#034;x&#034; &lt;&lt; 203 &lt;&lt; &#034;y&#034; &lt;&lt; 102 &lt;&lt; close_document;<\/p>\n<p>  collection.insert_one(builder.view());<br \/>\n   auto cursor &#061; collection.find({});<br \/>\n   for (auto&amp;&amp; doc : cursor) {<br \/>\n      std::cout &lt;&lt; bsoncxx::to_json(doc) &lt;&lt; std::endl;<br \/>\n  }<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u8be5\u7a0b\u5e8f\u8fde\u63a5\u81f3 MongoDB \u5b9e\u4f8b&#xff0c;\u5411\u96c6\u5408\u4e2d\u63d2\u5165\u6587\u6863&#xff0c;\u968f\u540e\u68c0\u7d22\u5e76\u6253\u5370\u8be5\u6587\u6863\u3002\u00a0\u9700\u6ce8\u610f&#xff0c;\u6b64\u4ee3\u7801\u8981\u6b63\u5e38\u8fd0\u884c&#xff0c;MongoDB \u5fc5\u987b\u5728\u540c\u4e00\u673a\u5668&#xff08;localhost&#xff09;\u7684\u6807\u51c6\u7aef\u53e3&#xff08;27017&#xff09;\u4e0a\u8fd0\u884c\u3002\u00a0\u82e5\u60a8\u7684 MongoDB \u5b9e\u4f8b\u8fd0\u884c\u4e8e\u4e0d\u540c\u4f4d\u7f6e&#xff0c;\u5219\u9700\u5728\u521b\u5efa\u5ba2\u6237\u7aef\u65f6\u63d0\u4f9b\u6b63\u786e\u7684\u8fde\u63a5 URI\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8fd9\u4e9b\u662f\u5728 C&#043;&#043;\u73af\u5883\u4e2d\u8fd0\u884c MongoDB \u5fc5\u987b\u91c7\u53d6\u7684\u5173\u952e\u4e3b\u8981\u6b65\u9aa4\u3002\u00a0\u4ece\u6b64\u523b\u8d77&#xff0c;\u60a8\u5c06\u80fd\u591f\u5f00\u59cb\u6784\u5efa\u66f4\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u8fd9\u4e9b\u7a0b\u5e8f\u53ef\u4ee5\u8bfb\u53d6\u3001\u5199\u5165\u3001\u66f4\u65b0\u548c\u5220\u9664 MongoDB \u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u3002<\/span><\/p>\n<h2 id=\"aid_185\" style=\"text-align:justify\"><span style=\"color:#000000\">\u5168\u6808\u5e94\u7528\u7684\u6570\u636e\u5e93\u67b6\u6784<\/span><\/h2>\n<p><span style=\"color:#000000\">MongoDB \u4f7f\u7528 BSON&#xff08;\u4e00\u79cd\u7c7b\u4f3c JSON \u6587\u6863\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f&#xff09;\u6765\u5b58\u50a8\u6570\u636e\u3002\u00a0\u4e0e SQL \u6570\u636e\u5e93\u4e0d\u540c&#xff0c;MongoDB \u662f\u65e0\u6a21\u5f0f\u7684\u3002\u00a0\u8fd9\u610f\u5473\u7740\u540c\u4e00\u96c6\u5408\u4e2d\u7684\u6587\u6863\u4e0d\u9700\u8981\u5177\u6709\u76f8\u540c\u7684\u5b57\u6bb5\u96c6&#xff0c;\u5e76\u4e14\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\u5728\u96c6\u5408\u5185\u7684\u4e0d\u540c\u6587\u6863\u95f4\u53ef\u4ee5\u6709\u6240\u4e0d\u540c\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5c3d\u7ba1\u5982\u6b64&#xff0c;\u4e3a\u4e86\u83b7\u5f97\u6700\u4f73\u6027\u80fd&#xff0c;\u7cbe\u5fc3\u8bbe\u8ba1\u6570\u636e\u6a21\u578b\u4ecd\u7136\u81f3\u5173\u91cd\u8981\u3002\u00a0\u5728 MongoDB \u4e2d&#xff0c;\u60a8\u5e94\u8be5\u6839\u636e\u5e94\u7528\u7a0b\u5e8f\u7684\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f&#xff0c;\u5728\u5d4c\u5165\u5b50\u6587\u6863\u548c\u521b\u5efa\u65b0\u96c6\u5408\u4e4b\u95f4\u5bfb\u6c42\u5e73\u8861\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5047\u8bbe\u7684\u535a\u5ba2\u5e94\u7528\u7684 MongoDB \u6a21\u5f0f\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>{<br \/>\n   &#034;user&#034;: {<br \/>\n       &#034;username&#034;: &#034;john_doe&#034;,<br \/>\n       &#034;email&#034;: &#034;john&#064;myblogapp.com&#034;,<br \/>\n       &#034;password&#034;: &#034;hashed_password&#034;,<br \/>\n       &#034;profiles&#034;: [<br \/>\n           {<br \/>\n               &#034;platform&#034;: &#034;twitter&#034;,<br \/>\n               &#034;handle&#034;: &#034;&#064;johndoe&#034;<br \/>\n           },<br \/>\n           {<br \/>\n               &#034;platform&#034;: &#034;instagram&#034;,<br \/>\n               &#034;handle&#034;: &#034;&#064;johndoeig&#034;<br \/>\n           }<br \/>\n       ]<br \/>\n   },<br \/>\n   &#034;posts&#034;: [<br \/>\n       {<br \/>\n           &#034;title&#034;: &#034;My first blog post&#034;,<br \/>\n           &#034;content&#034;: &#034;This is my first blog post&#034;,<br \/>\n           &#034;user&#034;: &#034;john_doe&#034;,<br \/>\n           &#034;comments&#034;: [<br \/>\n               {<br \/>\n                   &#034;user&#034;: &#034;commenter1&#034;,<br \/>\n                   &#034;content&#034;: &#034;Great post!&#034;,<br \/>\n                   &#034;timestamp&#034;: &#034;2023-07-01T14:00:00Z&#034;<br \/>\n               },<br \/>\n               {<br \/>\n                   &#034;user&#034;: &#034;commenter2&#034;,<br \/>\n                   &#034;content&#034;: &#034;Thanks for sharing!&#034;,<br \/>\n                   &#034;timestamp&#034;: &#034;2023-07-01T15:00:00Z&#034;<br \/>\n               }<br \/>\n           ],<br \/>\n           &#034;tags&#034;: [&#034;intro&#034;, &#034;first&#034;, &#034;blog&#034;],<br \/>\n           &#034;published_date&#034;: &#034;2023-07-01T12:00:00Z&#034;<br \/>\n       }<br \/>\n   ]<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u5728\u6b64\u67b6\u6784\u4e2d&#xff1a;<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u6bcf\u4e2a\u7528\u6237\u62e5\u6709\u7528\u6237\u540d\u3001\u7535\u5b50\u90ae\u7bb1\u3001\u54c8\u5e0c\u5bc6\u7801\u4ee5\u53ca\u5305\u542b\u793e\u4ea4\u5a92\u4f53\u8d26\u53f7\u7684 profiles \u6570\u7ec4\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u5e16\u5b50\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d&#xff0c;\u6bcf\u4e2a\u5e16\u5b50\u5305\u542b\u6807\u9898\u3001\u5185\u5bb9\u3001\u4f5c\u8005\u7528\u6237\u540d\u3001\u8bc4\u8bba\u3001\u6807\u7b7e\u548c\u53d1\u5e03\u65e5\u671f\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u8bc4\u8bba\u5b58\u50a8\u5728\u6bcf\u4e2a\u5e16\u5b50\u7684\u6570\u7ec4\u4e2d&#xff0c;\u5305\u542b\u8bc4\u8bba\u8005\u7528\u6237\u540d\u3001\u8bc4\u8bba\u5185\u5bb9\u548c\u8bc4\u8bba\u65f6\u95f4\u6233\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8fd9\u79cd\u8bbe\u8ba1\u5c06\u76f8\u5173\u6570\u636e\u5d4c\u5165\u5230\u5355\u4e00\u6587\u6863\u4e2d&#xff0c;\u53ef\u901a\u8fc7\u4e00\u6b21\u67e5\u8be2\u83b7\u53d6\u3002\u00a0\u8fd9\u79cd\u65b9\u5f0f\u7279\u522b\u9002\u5408\u9700\u8981\u9891\u7e41\u540c\u65f6\u8bbf\u95ee\u7684\u6570\u636e&#xff08;\u5982\u7528\u6237\u8d44\u6599\u6216\u535a\u5ba2\u8bc4\u8bba&#xff09;&#xff0c;\u4e14\u9002\u7528\u4e8e\u4e0d\u4f1a\u5bfc\u81f4\u6570\u7ec4\u65e0\u9650\u589e\u957f\u7684\u4e00\u5bf9\u591a\u5173\u7cfb\u3002\u00a0\u82e5\u5173\u7cfb\u4f1a\u5bfc\u81f4\u6570\u636e\u65e0\u9650\u589e\u957f&#xff0c;\u5219\u66f4\u9002\u5408\u4f7f\u7528\u5f15\u7528\u548c\u72ec\u7acb\u96c6\u5408\u3002\u00a0\u5177\u4f53\u51b3\u7b56\u9700\u6839\u636e\u60a8\u7684\u4f7f\u7528\u573a\u666f\u53ca\u5e94\u7528\u7a0b\u5e8f\u4e0e\u6570\u636e\u7684\u4ea4\u4e92\u65b9\u5f0f\u800c\u5b9a\u3002<\/span><\/p>\n<h2 id=\"aid_253\" style=\"text-align:justify\"><span style=\"color:#000000\">\u6267\u884c CRUD \u64cd\u4f5c<\/span><\/h2>\n<p><span style=\"color:#000000\">CRUD \u64cd\u4f5c\u662f\u4efb\u4f55\u6d89\u53ca\u6301\u4e45\u5316\u5b58\u50a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u7840\u3002CRUD \u4ee3\u8868\u521b\u5efa(Create)\u3001\u8bfb\u53d6(Read)\u3001\u66f4\u65b0(Update)\u548c\u5220\u9664(Delete)\u2014\u2014\u8fd9\u662f\u5bf9\u4efb\u4f55\u6301\u4e45\u5316\u5b58\u50a8\u7684\u56db\u79cd\u57fa\u672c\u64cd\u4f5c\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8ba9\u6211\u4eec\u4ee5\u535a\u5ba2\u5e94\u7528\u4e3a\u4f8b&#xff0c;\u770b\u770b\u5982\u4f55\u4f7f\u7528 C&#043;&#043; MongoDB \u9a71\u52a8\u5728 MongoDB \u4e2d\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"394\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729213204-68893dd442174.png\" width=\"898\" \/><\/p>\n<p><span style=\"color:#000000\">\u56fe 5.1 MongoDB \u7684 CRUD \u64cd\u4f5c<\/span><\/p>\n<p><span style=\"color:#000000\">\u521b\u5efa<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728 MongoDB \u4e2d\u63d2\u5165\u65b0\u6587\u6863\u4f7f\u7528 insert_one \u6216 insert_many \u51fd\u6570\u5b9e\u73b0\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u521b\u5efa\u65b0\u7528\u6237&#xff1a;<\/span><\/p>\n<p>mongocxx::collection user_collection &#061; db[&#034;users&#034;];<br \/>\nbsoncxx::builder::stream::document user_doc{};<br \/>\nuser_doc &lt;&lt; &#034;username&#034; &lt;&lt; &#034;new_user&#034;<br \/>\n        &lt;&lt; &#034;email&#034; &lt;&lt; &#034;new_user&#064;myblogapp.com&#034;<br \/>\n        &lt;&lt; &#034;password&#034; &lt;&lt; &#034;hashed_password&#034;;<br \/>\nuser_collection.insert_one(user_doc.view());<\/p>\n<p><span style=\"color:#000000\">\u4e0a\u8ff0\u4ee3\u7801\u7247\u6bb5\u5c55\u793a\u4e86\u5982\u4f55\u5411&#039;users&#039;\u96c6\u5408\u6dfb\u52a0\u65b0\u7528\u6237\u3002\u00a0\u6211\u4eec\u4f7f\u7528\u6784\u5efa\u5668 API \u521b\u5efa BSON \u6587\u6863&#xff0c;\u7136\u540e\u901a\u8fc7 insert_one \u51fd\u6570\u63d2\u5165\u8be5\u6587\u6863\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8bfb\u53d6<\/span><\/p>\n<p><span style=\"color:#000000\">\u8981\u4ece MongoDB \u96c6\u5408\u4e2d\u8bfb\u53d6\u6587\u6863&#xff0c;\u6211\u4eec\u4f7f\u7528 find \u51fd\u6570\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u6309\u7528\u6237\u540d\u67e5\u627e\u7528\u6237&#xff1a;<\/span><\/p>\n<p>bsoncxx::builder::stream::document filter_builder;<br \/>\nfilter_builder &lt;&lt; &#034;username&#034; &lt;&lt; &#034;new_user&#034;;<br \/>\nbsoncxx::stdx::optional&lt;bsoncxx::document::value&gt; maybe_result &#061; user_collection.find_one(filter_builder.view());<br \/>\nif(maybe_result) {<br \/>\n   std::cout &lt;&lt; bsoncxx::to_json(*maybe_result) &lt;&lt; &#034;\\\\n&#034;;<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u5728\u4e0a\u8ff0\u4ee3\u7801\u7247\u6bb5\u4e2d&#xff0c;\u6211\u4eec\u6784\u5efa\u4e86\u4e00\u4e2a\u7528\u6237\u540d\u4e3a&#034;new_user&#034;\u7684\u7b5b\u9009\u6587\u6863&#xff0c;\u7136\u540e\u5c06\u8be5\u7b5b\u9009\u6761\u4ef6\u4f20\u9012\u7ed9 find_one \u51fd\u6570\u4ee5\u67e5\u627e\u5339\u914d\u7684\u6587\u6863\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u66f4\u65b0<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728 MongoDB \u4e2d\u66f4\u65b0\u6587\u6863&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 update_one \u6216 update_many \u51fd\u6570\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8981\u66f4\u6539\u7528\u6237\u7684\u7535\u5b50\u90ae\u4ef6&#xff1a;<\/span><\/p>\n<p>bsoncxx::builder::stream::document update_doc;<br \/>\nupdate_doc &lt;&lt; &#034;$set&#034; &lt;&lt; bsoncxx::builder::stream::open_document<br \/>\n          &lt;&lt; &#034;email&#034; &lt;&lt; &#034;new_email&#064;myblogapp.com&#034;<br \/>\n          &lt;&lt; bsoncxx::builder::stream::close_document;<br \/>\nuser_collection.update_one(filter_builder.view(), update_doc.view());<\/p>\n<p><span style=\"color:#000000\">\u6211\u4eec\u6b63\u5728\u521b\u5efa\u4e00\u4e2a\u66f4\u65b0\u6587\u6863&#xff0c;\u4f7f\u7528$set \u64cd\u4f5c\u7b26\u6765\u66f4\u6539\u5339\u914d\u6587\u6863\u7684 email \u5b57\u6bb5\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5220\u9664<\/span><\/p>\n<p><span style=\"color:#000000\">\u8981\u5220\u9664\u6587\u6863&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 delete_one \u6216 delete_many \u51fd\u6570\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5220\u9664\u7528\u6237&#xff1a;<\/span><\/p>\n<p>user_collection.delete_one(filter_builder.view());<\/p>\n<p><span style=\"color:#000000\">\u8fd9\u884c\u4ee3\u7801\u4f1a\u4ece&#039;users&#039;\u96c6\u5408\u4e2d\u5220\u9664\u7528\u6237\u540d\u4e3a&#034;new_user&#034;\u7684\u7528\u6237\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4e0a\u8ff0\u6240\u6709\u64cd\u4f5c\u4e2d&#xff0c;\u4e3a\u7b80\u6d01\u8d77\u89c1\u7701\u7565\u4e86\u9519\u8bef\u68c0\u67e5&#xff0c;\u4f46\u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u60a8\u5e94\u8be5\u59cb\u7ec8\u68c0\u67e5\u8fd9\u4e9b\u64cd\u4f5c\u7684\u7ed3\u679c\u662f\u5426\u5b58\u5728\u9519\u8bef\u6216\u5f02\u5e38\u3002\u00a0\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u662f\u5f02\u6b65\u7684&#xff0c;C&#043;&#043; MongoDB \u9a71\u52a8\u63d0\u4f9b\u4e86\u591a\u79cd\u5904\u7406\u8fd9\u79cd\u5f02\u6b65\u6027\u7684\u65b9\u6cd5\u3002\u00a0\u5bf9\u4e8e\u590d\u6742\u5e94\u7528&#xff0c;\u901a\u5e38\u4f1a\u4f7f\u7528\u805a\u5408\u51fd\u6570&#xff0c;\u5b83\u5141\u8bb8\u5728\u670d\u52a1\u5668\u7aef\u8fdb\u884c\u590d\u6742\u7684\u6570\u636e\u64cd\u4f5c\u548c\u8f6c\u6362\u3002<\/span><\/p>\n<h2 id=\"aid_242\" style=\"text-align:justify\"><span style=\"color:#000000\">\u6267\u884c\u590d\u6742\u67e5\u8be2&#xff1a;\u805a\u5408\u4e0e\u7d22\u5f15<\/span><\/h2>\n<p><span style=\"color:#000000\">\u805a\u5408\u4e0e\u7d22\u5f15\u662f MongoDB \u7684\u4e24\u5927\u5f3a\u5927\u529f\u80fd&#xff0c;\u4f7f\u6211\u4eec\u80fd\u591f\u6267\u884c\u590d\u6742\u67e5\u8be2\u3001\u7b5b\u9009\u548c\u6392\u5e8f\u6570\u636e&#xff0c;\u5e76\u63d0\u9ad8\u6570\u636e\u5e93\u64cd\u4f5c\u6548\u7387\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u6267\u884c\u805a\u5408\u64cd\u4f5c<\/span><\/p>\n<p><span style=\"color:#000000\">MongoDB \u4e2d\u7684\u805a\u5408\u662f\u5bf9\u96c6\u5408\u4e2d\u6587\u6863\u6267\u884c\u590d\u6742\u6570\u636e\u5206\u6790\u7684\u4e00\u79cd\u65b9\u5f0f\u3002\u00a0\u5b83\u63d0\u4f9b\u4e86\u5904\u7406\u6570\u636e\u8bb0\u5f55\u5e76\u8fd4\u56de\u8ba1\u7b97\u7ed3\u679c\u7684\u65b9\u6cd5\u3002\u00a0\u805a\u5408\u64cd\u4f5c\u53ef\u4ee5\u5c06\u591a\u4e2a\u6587\u6863\u4e2d\u7684\u503c\u5206\u7ec4&#xff0c;\u5e76\u5bf9\u5206\u7ec4\u540e\u7684\u6570\u636e\u6267\u884c\u5404\u79cd\u64cd\u4f5c\u4ee5\u8fd4\u56de\u5355\u4e00\u7ed3\u679c\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4f8b\u5982&#xff0c;\u5728\u4e00\u4e2a\u535a\u5ba2\u5e94\u7528\u4e2d&#xff0c;\u60a8\u53ef\u80fd\u60f3\u77e5\u9053\u6bcf\u4e2a\u7528\u6237\u53d1\u8868\u4e86\u591a\u5c11\u7bc7\u6587\u7ae0\u3002\u00a0\u8fd9\u53ef\u4ee5\u901a\u8fc7 MongoDB \u7684\u805a\u5408\u6846\u67b6\u5b9e\u73b0\u3002$group \u9636\u6bb5\u4f1a\u6309\u7167\u6307\u5b9a\u7684\u6807\u8bc6\u8868\u8fbe\u5f0f\u5bf9\u8f93\u5165\u6587\u6863\u8fdb\u884c\u5206\u7ec4&#xff0c;\u5e76\u4e3a\u6bcf\u4e2a\u552f\u4e00\u5206\u7ec4\u8f93\u51fa\u4e00\u4e2a\u6587\u6863\u3002\u00a0\u7136\u540e\u4f7f\u7528$sum \u64cd\u4f5c\u7b26\u4e3a\u6bcf\u4e2a\u7ec4\u9012\u589e\u8ba1\u6570\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u5982\u4e0b&#xff1a;<\/span><\/p>\n<p>mongocxx::collection posts_collection &#061; db[&#034;posts&#034;];<br \/>\nbsoncxx::builder::stream::document group_stage;<br \/>\ngroup_stage &lt;&lt; &#034;$group&#034; &lt;&lt; bsoncxx::builder::stream::open_document<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;&lt; &#034;_id&#034; &lt;&lt; &#034;$username&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;&lt; &#034;count&#034; &lt;&lt; bsoncxx::builder::stream::open_document &lt;&lt; &#034;$sum&#034; &lt;&lt; 1<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;&lt; bsoncxx::builder::stream::close_document<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;&lt; bsoncxx::builder::stream::close_document;<br \/>\nmongocxx::pipeline p{};<br \/>\np.group(group_stage.view());<br \/>\nauto cursor &#061; posts_collection.aggregate(p, mongocxx::options::aggregate{});<br \/>\nfor(auto doc : cursor) {<br \/>\n\u00a0 \u00a0std::cout &lt;&lt; bsoncxx::to_json(doc) &lt;&lt; &#034;\\\\n&#034;;<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u4e0a\u8ff0\u4ee3\u7801\u7247\u6bb5\u4e2d&#xff0c;\u6211\u4eec\u4f7f\u7528\u4e86 MongoDB \u7684\u805a\u5408\u6846\u67b6\u3002$group \u9636\u6bb5\u901a\u8fc7\u6307\u5b9a\u7684_id \u8868\u8fbe\u5f0f&#xff08;\u672c\u4f8b\u4e2d\u4e3a username \u5b57\u6bb5&#xff09;\u5bf9\u8f93\u5165\u6587\u6863\u8fdb\u884c\u5206\u7ec4&#xff0c;\u5e76\u4e3a\u6bcf\u4e2a\u4e0d\u540c\u7684\u5206\u7ec4\u8f93\u51fa\u4e00\u4e2a\u6587\u6863\u3002$sum \u8868\u8fbe\u5f0f\u7528\u4e8e\u9012\u589e\u6bcf\u4e2a\u7ec4\u7684\u8ba1\u6570\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u521b\u5efa\u7d22\u5f15<\/span><\/p>\n<p><span style=\"color:#000000\">MongoDB \u4e2d\u7684\u7d22\u5f15\u4e0e\u5176\u4ed6\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u7684\u7d22\u5f15\u5177\u6709\u76f8\u540c\u7684\u4f5c\u7528\u3002\u00a0\u7d22\u5f15\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784&#xff0c;\u5b83\u4ee5\u6613\u4e8e\u904d\u5386\u7684\u5f62\u5f0f\u4fdd\u5b58\u96c6\u5408\u6570\u636e\u7684\u5b50\u96c6\u3002\u00a0\u8be5\u7d22\u5f15\u5b58\u50a8\u7279\u5b9a\u5b57\u6bb5\u6216\u5b57\u6bb5\u96c6\u7684\u503c&#xff0c;\u5e76\u6309\u7d22\u5f15\u4e2d\u6307\u5b9a\u7684\u5b57\u6bb5\u503c\u6392\u5e8f\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u521b\u5efa\u7d22\u5f15\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u641c\u7d22\u64cd\u4f5c\u7684\u6027\u80fd\u3002\u00a0\u4f8b\u5982&#xff0c;\u5728&#034;username&#034;\u5b57\u6bb5\u4e0a\u521b\u5efa\u5347\u5e8f\u7d22\u5f15\u610f\u5473\u7740 MongoDB \u53ef\u4ee5\u4f7f\u7528\u8be5\u7d22\u5f15\u6765\u7b5b\u9009 username \u5b57\u6bb5\u7684\u67e5\u8be2&#xff0c;\u4ece\u800c\u52a0\u5feb\u8fd9\u4e9b\u67e5\u8be2\u901f\u5ea6\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8ba9\u6211\u4eec\u5728 users \u96c6\u5408\u7684 username \u5b57\u6bb5\u4e0a\u521b\u5efa\u5982\u4e0b\u7d22\u5f15&#xff1a;<\/span><\/p>\n<p>bsoncxx::builder::stream::document index_builder;<br \/>\nindex_builder &lt;&lt; &#034;username&#034; &lt;&lt; 1;<br \/>\nuser_collection.create_index(index_builder.view(), {});<\/p>\n<p><span style=\"color:#000000\">\u5728\u4e0a\u8ff0\u4ee3\u7801\u7247\u6bb5\u4e2d&#xff0c;\u6211\u4eec\u6b63\u5728&#034;username&#034;\u5b57\u6bb5\u4e0a\u521b\u5efa\u4e00\u4e2a\u5347\u5e8f\u7d22\u5f15\u3002\u00a0\u8fd9\u610f\u5473\u7740 MongoDB \u53ef\u4ee5\u4f7f\u7528\u8be5\u7d22\u5f15\u6765\u7b5b\u9009 username \u5b57\u6bb5\u7684\u67e5\u8be2&#xff0c;\u4ece\u800c\u663e\u8457\u63d0\u9ad8\u8fd9\u4e9b\u67e5\u8be2\u7684\u901f\u5ea6\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7d22\u5f15\u5b58\u5728\u4e00\u4e9b\u6743\u8861&#xff0c;\u5b83\u4eec\u53ef\u4ee5\u6781\u5927\u63d0\u9ad8\u8bfb\u53d6\u901f\u5ea6&#xff0c;\u4f46\u4f1a\u964d\u4f4e\u5199\u5165\u901f\u5ea6&#xff0c;\u56e0\u4e3a\u6bcf\u6b21\u63d2\u5165\u6216\u66f4\u65b0\u6587\u6863\u65f6 MongoDB \u90fd\u9700\u8981\u66f4\u65b0\u7d22\u5f15\u3002\u00a0\u91cd\u8981\u7684\u662f\u627e\u5230\u5408\u9002\u7684\u5e73\u8861\u70b9&#xff0c;\u53ea\u4e3a\u7ecf\u5e38\u67e5\u8be2\u7684\u5b57\u6bb5\u521b\u5efa\u7d22\u5f15\u3002<\/span><\/p>\n<h2 id=\"aid_125\" style=\"text-align:justify\"><span style=\"color:#000000\">\u603b\u7ed3<\/span><\/h2>\n<p><span style=\"color:#000000\">\u672c\u7ae0\u6211\u4eec\u6df1\u5165\u63a2\u8ba8\u4e86\u6570\u636e\u5e93\u7684\u4e16\u754c&#xff0c;\u7279\u522b\u805a\u7126\u4e8e MongoDB \u53ca\u5176\u5982\u4f55\u4e0e\u6211\u4eec\u7528 C&#043;&#043;\u7f16\u5199\u7684\u540e\u7aef\u7f16\u7a0b\u8fdb\u884c\u96c6\u6210\u3002\u00a0\u9996\u5148&#xff0c;\u6211\u4eec\u7740\u91cd\u7406\u89e3\u4e86\u6570\u636e\u5e93\u5728\u5e94\u7528\u5f00\u53d1\u4e2d\u7684\u57fa\u7840\u4f5c\u7528&#xff0c;\u4ee5\u53ca\u5728\u540e\u7aef\u6267\u884c\u7684\u5404\u79cd\u64cd\u4f5c\u3002\u00a0\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf&#xff0c;\u5c24\u5176\u662f MongoDB&#xff0c;\u662f\u73b0\u4ee3\u5168\u6808\u5e94\u7528\u4e0d\u53ef\u6216\u7f3a\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u00a0\u8fd9\u4e00\u7ec4\u4ef6\u4e4b\u6240\u4ee5\u5fc5\u8981&#xff0c;\u662f\u56e0\u4e3a\u5b83\u80fd\u591f\u5b58\u50a8\u3001\u68c0\u7d22\u548c\u64cd\u4f5c\u9a71\u52a8\u7528\u6237\u754c\u9762\u6240\u9700\u7684\u6570\u636e\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u6211\u4eec\u4ee5\u517c\u5bb9 C&#043;&#043;\u5f00\u53d1\u73af\u5883\u7684\u65b9\u5f0f\u7ee7\u7eed\u4e86 MongoDB \u7684\u5b89\u88c5\u548c\u914d\u7f6e\u8fc7\u7a0b\u3002\u00a0\u60a8\u5df2\u7ecf\u4e86\u89e3\u5230 MongoDB \u4f5c\u4e3a NoSQL \u6570\u636e\u5e93&#xff0c;\u5728\u5176\u4f7f\u7528\u7684\u6570\u636e\u7ed3\u6784\u65b9\u9762\u5177\u6709\u7075\u6d3b\u6027&#xff0c;\u540c\u65f6\u5177\u5907\u53ef\u6269\u5c55\u6027\u548c\u6570\u636e\u5e93\u67e5\u8be2\u80fd\u529b\u3002\u00a0\u6211\u4eec\u8ba8\u8bba\u4e86 MongoDB \u4e2d\u7684\u6a21\u5f0f\u8bbe\u8ba1&#xff0c;\u91cd\u70b9\u63a2\u8ba8\u4e86\u5728\u53ef\u80fd\u60c5\u51b5\u4e0b\u4f18\u5148\u91c7\u7528\u975e\u89c4\u8303\u5316\u6216\u6587\u6863\u5d4c\u5165\u7684\u65b9\u5f0f\u3002\u00a0\u6211\u4eec\u8ba4\u8bc6\u5230 MongoDB \u6a21\u5f0f\u5728\u6027\u80fd\u548c\u53ef\u6269\u5c55\u6027\u65b9\u9762\u76f8\u6bd4\u4f20\u7edf\u5173\u7cfb\u578b\u6570\u636e\u5e93\u6240\u5177\u6709\u7684\u4f18\u52bf\u3002\u00a0\u901a\u8fc7\u4e00\u4e2a\u535a\u5ba2\u5e94\u7528\u793a\u4f8b&#xff0c;\u6211\u4eec\u63a2\u8ba8\u4e86\u6a21\u5f0f\u8bbe\u8ba1\u7684\u8003\u91cf\u56e0\u7d20&#xff0c;\u8fd9\u4e3a\u540e\u7eed\u7684\u6570\u636e\u5e93\u4ea4\u4e92\u5960\u5b9a\u4e86\u575a\u5b9e\u57fa\u7840\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728 MongoDB \u5b9e\u73b0\u7684\u6700\u540e\u4e00\u6b65\u4e2d&#xff0c;\u6211\u4eec\u6df1\u5165\u63a2\u8ba8\u4e86 CRUD \u64cd\u4f5c&#xff08;\u5373\u521b\u5efa\u3001\u8bfb\u53d6\u3001\u66f4\u65b0\u548c\u5220\u9664&#xff09;\u3002\u00a0\u4e3a\u4e86\u5e2e\u52a9\u60a8\u7406\u89e3\u540e\u7aef\u4e0e\u6570\u636e\u5e93\u7684\u4ea4\u4e92&#xff0c;\u6211\u4eec\u5206\u89e3\u4e86\u8fd9\u4e9b\u57fa\u7840\u64cd\u4f5c&#xff0c;\u5e76\u63d0\u4f9b\u4e86\u5206\u6b65\u793a\u4f8b\u53ca\u4ee3\u7801\u7247\u6bb5\u3002\u00a0\u968f\u540e\u6211\u4eec\u8ba8\u8bba\u4e86\u5305\u542b\u805a\u5408\u4e0e\u7d22\u5f15\u7684\u590d\u6742\u67e5\u8be2\u3002\u00a0\u901a\u8fc7\u591a\u4e2a\u5b9e\u9645\u6848\u4f8b&#xff0c;\u6211\u4eec\u638c\u63e1\u4e86\u5982\u4f55\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\u548c\u64cd\u4f5c&#xff0c;\u4ee5\u53ca\u7d22\u5f15\u5982\u4f55\u901a\u8fc7\u4e0d\u540c\u5e94\u7528\u573a\u666f\u663e\u8457\u63d0\u5347\u67e5\u8be2\u6027\u80fd\u3002\u00a0\u8fd9\u4e9b\u9ad8\u7ea7\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u5e94\u7528\u4e3a\u540e\u7aef\u5f00\u53d1\u6d41\u7a0b\u5f00\u8f9f\u4e86\u65b0\u9014\u5f84&#xff0c;\u80fd\u66f4\u9ad8\u6548\u5730\u5b9e\u73b0\u6570\u636e\u64cd\u4f5c\u4e0e\u68c0\u7d22\u3002\u00a0\u672c\u7ae0\u6240\u83b7\u77e5\u8bc6\u4e3a\u5f00\u53d1\u6d89\u53ca\u6570\u636e\u5e93\u4ea4\u4e92\u4e0e\u64cd\u4f5c\u7684\u540e\u7aef\u5e94\u7528\u5960\u5b9a\u4e86\u575a\u5b9e\u57fa\u7840\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb949\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u9700\u6c42\u5e94\u6307\u5bfc\u6570\u636e\u5e93\u7684\u9009\u62e9\uff0c\u53ef\u4ee5\u662f\u4f20\u7edf\u7684 SQL \u6570\u636e\u5e93\uff08\u5982 MySQL \u6216 PostgreSQL\uff09\uff0c\u4e5f\u53ef\u4ee5\u662f NoSQL \u6570\u636e\u5e93\uff08\u5982 MongoDB \u6216 Cassandra\uff09\u3002\u4e0e SQL \u6570\u636e\u5e93\u4e0d\u540c\uff0cMongoDB \u662f\u65e0\u6a21\u5f0f\u7684\u3002\u8fd9\u610f\u5473\u7740\u540c\u4e00\u96c6\u5408\u4e2d\u7684\u6587\u6863\u4e0d\u9700\u8981\u5177\u6709\u76f8\u540c\u7684\u5b57\u6bb5\u96c6\uff0c\u5e76\u4e14\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\u5728\u96c6\u5408\u5185\u7684\u4e0d\u540c\u6587\u6863\u95f4\u53ef\u4ee5\u6709\u6240\u4e0d\u540c\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u5355\u952e\u67e5\u8be2\u3001\u8303\u56f4\u67e5\u8be2\u3001\u6587\u672c\u641c\u7d22\u3001\u56fe\u5904\u7406\u4ee5\u53ca\u901a\u8fc7\u5b9e\u65f6\u805a\u5408\u5b9e\u73b0\u7684\u5730\u7406\u7a7a\u95f4\u67e5\u8be2\u7b49\u591a\u79cd\u65b9\u5f0f\uff0c\u6784\u5efa\u80fd\u591f\u7075\u6d3b\u67e5\u8be2\u5206\u6790\u6570\u636e\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u63d0\u4f9b\u5f3a\u5927\u7684\u6570\u636e\u8bbf\u95ee\u4e0e\u5206\u6790\u80fd\u529b\u3002_bson c++<\/p>\n","protected":false},"author":2,"featured_media":47016,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4489,733,100],"topic":[],"class_list":["post-47017","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-mongodb","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/47017.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb949\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u9700\u6c42\u5e94\u6307\u5bfc\u6570\u636e\u5e93\u7684\u9009\u62e9\uff0c\u53ef\u4ee5\u662f\u4f20\u7edf\u7684 SQL \u6570\u636e\u5e93\uff08\u5982 MySQL \u6216 PostgreSQL\uff09\uff0c\u4e5f\u53ef\u4ee5\u662f NoSQL \u6570\u636e\u5e93\uff08\u5982 MongoDB \u6216 Cassandra\uff09\u3002\u4e0e SQL \u6570\u636e\u5e93\u4e0d\u540c\uff0cMongoDB \u662f\u65e0\u6a21\u5f0f\u7684\u3002\u8fd9\u610f\u5473\u7740\u540c\u4e00\u96c6\u5408\u4e2d\u7684\u6587\u6863\u4e0d\u9700\u8981\u5177\u6709\u76f8\u540c\u7684\u5b57\u6bb5\u96c6\uff0c\u5e76\u4e14\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\u5728\u96c6\u5408\u5185\u7684\u4e0d\u540c\u6587\u6863\u95f4\u53ef\u4ee5\u6709\u6240\u4e0d\u540c\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u5355\u952e\u67e5\u8be2\u3001\u8303\u56f4\u67e5\u8be2\u3001\u6587\u672c\u641c\u7d22\u3001\u56fe\u5904\u7406\u4ee5\u53ca\u901a\u8fc7\u5b9e\u65f6\u805a\u5408\u5b9e\u73b0\u7684\u5730\u7406\u7a7a\u95f4\u67e5\u8be2\u7b49\u591a\u79cd\u65b9\u5f0f\uff0c\u6784\u5efa\u80fd\u591f\u7075\u6d3b\u67e5\u8be2\u5206\u6790\u6570\u636e\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u63d0\u4f9b\u5f3a\u5927\u7684\u6570\u636e\u8bbf\u95ee\u4e0e\u5206\u6790\u80fd\u529b\u3002_bson c++\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/47017.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T21:32:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729213204-68893dd442174.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47017.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/47017.html\",\"name\":\"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T21:32:05+00:00\",\"dateModified\":\"2025-07-29T21:32:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/47017.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/47017.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47017.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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:\/\/www.wsisp.com\/helps\/47017.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb949\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u9700\u6c42\u5e94\u6307\u5bfc\u6570\u636e\u5e93\u7684\u9009\u62e9\uff0c\u53ef\u4ee5\u662f\u4f20\u7edf\u7684 SQL \u6570\u636e\u5e93\uff08\u5982 MySQL \u6216 PostgreSQL\uff09\uff0c\u4e5f\u53ef\u4ee5\u662f NoSQL \u6570\u636e\u5e93\uff08\u5982 MongoDB \u6216 Cassandra\uff09\u3002\u4e0e SQL \u6570\u636e\u5e93\u4e0d\u540c\uff0cMongoDB \u662f\u65e0\u6a21\u5f0f\u7684\u3002\u8fd9\u610f\u5473\u7740\u540c\u4e00\u96c6\u5408\u4e2d\u7684\u6587\u6863\u4e0d\u9700\u8981\u5177\u6709\u76f8\u540c\u7684\u5b57\u6bb5\u96c6\uff0c\u5e76\u4e14\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\u5728\u96c6\u5408\u5185\u7684\u4e0d\u540c\u6587\u6863\u95f4\u53ef\u4ee5\u6709\u6240\u4e0d\u540c\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u5355\u952e\u67e5\u8be2\u3001\u8303\u56f4\u67e5\u8be2\u3001\u6587\u672c\u641c\u7d22\u3001\u56fe\u5904\u7406\u4ee5\u53ca\u901a\u8fc7\u5b9e\u65f6\u805a\u5408\u5b9e\u73b0\u7684\u5730\u7406\u7a7a\u95f4\u67e5\u8be2\u7b49\u591a\u79cd\u65b9\u5f0f\uff0c\u6784\u5efa\u80fd\u591f\u7075\u6d3b\u67e5\u8be2\u5206\u6790\u6570\u636e\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u63d0\u4f9b\u5f3a\u5927\u7684\u6570\u636e\u8bbf\u95ee\u4e0e\u5206\u6790\u80fd\u529b\u3002_bson c++","og_url":"https:\/\/www.wsisp.com\/helps\/47017.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T21:32:05+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729213204-68893dd442174.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/47017.html","url":"https:\/\/www.wsisp.com\/helps\/47017.html","name":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T21:32:05+00:00","dateModified":"2025-07-29T21:32:05+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/47017.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/47017.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/47017.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 5 \u4f7f\u7528 MongoDB \u7ba1\u7406\u6570\u636e\u5e93\u64cd\u4f5c"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=47017"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47017\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/47016"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=47017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=47017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=47017"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=47017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}