{"id":5556,"date":"2024-11-14T09:02:24","date_gmt":"2024-11-14T01:02:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5556\/"},"modified":"2024-11-14T09:02:24","modified_gmt":"2024-11-14T01:02:24","slug":"mongodb%e6%80%8e%e4%b9%88%e6%9f%a5%e8%af%a2%e5%88%86%e9%a1%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5556\/","title":{"rendered":"mongodb\u600e\u4e48\u67e5\u8be2\u5206\u9875"},"content":{"rendered":"<blockquote><p>\n  mongodb \u63d0\u4f9b\u591a\u79cd\u5206\u9875\u67e5\u8be2\u65b9\u6cd5\uff1a\u4f7f\u7528 skip() \u548c limit() \u65b9\u6cd5\uff1a\u8df3\u8fc7\u6307\u5b9a\u6570\u91cf\u7684\u6570\u636e\u5e76\u8fd4\u56de\u6307\u5b9a\u6570\u91cf\u7684\u6570\u636e\u3002\u4f7f\u7528 aggregate() \u7ba1\u9053\uff1a\u63d0\u4f9b\u66f4\u7075\u6d3b\u7684\u5206\u9875\u9009\u9879\uff0c\u53ef\u4e0e\u5176\u4ed6\u805a\u5408\u64cd\u4f5c\u7ed3\u5408\u4f7f\u7528\u3002\u4f7f\u7528\u6e38\u6807\uff1a\u5141\u8bb8\u6309\u9700\u4ee5\u8fed\u4ee3\u65b9\u5f0f\u8bbf\u95ee\u67e5\u8be2\u7ed3\u679c\u5e76\u652f\u6301\u5206\u9875\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052918121660139.jpg\" class=\"aligncenter\" title=\"mongodb\u600e\u4e48\u67e5\u8be2\u5206\u9875\u63d2\u56fe\" alt=\"mongodb\u600e\u4e48\u67e5\u8be2\u5206\u9875\u63d2\u56fe\" \/><\/p>\n<p><strong>MongoDB\u5206\u9875\u67e5\u8be2<\/strong><\/p>\n<p>MongoDB\u4e2d\u63d0\u4f9b\u591a\u79cd\u65b9\u6cd5\u8fdb\u884c\u5206\u9875\u67e5\u8be2\uff0c\u5305\u62ec\uff1a<\/p>\n<p><strong>skip()\u548climit()\u65b9\u6cd5<\/strong><\/p>\n<p>skip()\u65b9\u6cd5\u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u6570\u636e\u6761\u6570\uff0climit()\u65b9\u6cd5\u6307\u5b9a\u8981\u8fd4\u56de\u7684\u6570\u636e\u6761\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>db.collection.find().skip(10).limit(5);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u8df3\u8fc7\u524d10\u6761\u6570\u636e\uff0c\u5e76\u8fd4\u56de\u63a5\u4e0b\u6765\u76845\u6761\u6570\u636e\u3002<\/p>\n<p><strong>aggregate()\u7ba1\u9053<\/strong><\/p>\n<p>aggregate()\u7ba1\u9053\u63d0\u4f9b\u66f4\u7075\u6d3b\u7684\u5206\u9875\u9009\u9879\uff0c\u53ef\u4ee5\u4e0e\u5176\u4ed6\u805a\u5408\u64cd\u4f5c\u7ed3\u5408\u4f7f\u7528\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>db.collection.aggregate([\n  { $skip: 10 },\n  { $limit: 5 }\n]);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6e38\u6807<\/strong><\/p>\n<p>\u6e38\u6807\u5141\u8bb8\u4ee5\u8fed\u4ee3\u65b9\u5f0f\u8bbf\u95ee\u67e5\u8be2\u7ed3\u679c\uff0c\u5e76\u6309\u9700\u83b7\u53d6\u6570\u636e\u3002\u6e38\u6807\u652f\u6301\u5206\u9875\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>cursor.skip(10).limit(5);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u5206\u9875\u67e5\u8be2\u7684\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u4f7f\u7528\u9002\u5f53\u7684\u7d22\u5f15\uff0c\u4ee5\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u3002<\/li>\n<li>\u5982\u679c\u6570\u636e\u96c6\u5f88\u5927\uff0c\u8bf7\u8003\u8651\u4f7f\u7528\u6e38\u6807\u6216aggregate()\u7ba1\u9053\u8fdb\u884c\u5206\u9875\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u6027\u8fd4\u56de\u6240\u6709\u6570\u636e\u3002<\/li>\n<li>\u5bf9\u4e8e\u901f\u5ea6\u81f3\u5173\u91cd\u8981\u7684\u5e94\u7528\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Mongodb Atlas\u641c\u7d22\u8fde\u63a5\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u5feb\u7684\u5206\u9875\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u67e5\u8be2\u5206\u9875\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mongodb \u63d0\u4f9b\u591a\u79cd\u5206\u9875\u67e5\u8be2\u65b9\u6cd5\uff1a\u4f7f\u7528 skip() \u548c limit() \u65b9\u6cd5\uff1a\u8df3\u8fc7\u6307\u5b9a\u6570\u91cf\u7684\u6570\u636e\u5e76\u8fd4\u56de\u6307\u5b9a\u6570\u91cf\u7684\u6570\u636e\u3002\u4f7f\u7528 aggregate() \u7ba1\u9053\uff1a\u63d0\u4f9b\u66f4\u7075\u6d3b\u7684\u5206\u9875\u9009\u9879\uff0c\u53ef\u4e0e\u5176\u4ed6\u805a\u5408\u64cd\u4f5c\u7ed3\u5408\u4f7f\u7528\u3002\u4f7f\u7528\u6e38\u6807\uff1a\u5141\u8bb8\u6309\u9700\u4ee5\u8fed\u4ee3\u65b9\u5f0f\u8bbf\u95ee\u67e5\u8be2\u7ed3\u679c\u5e76\u652f\u6301\u5206\u9875\u3002 MongoDB\u5206\u9875\u67e5\u8be2 MongoDB\u4e2d\u63d0\u4f9b\u591a\u79cd\u65b9\u6cd5\u8fdb\u884c\u5206\u9875\u67e5\u8be2\uff0c\u5305\u62ec\uff1a skip()\u548climit()\u65b9\u6cd5 skip()\u65b9\u6cd5\u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u6570\u636e\u6761\u6570\uff0climit()\u65b9\u6cd5\u6307\u5b9a\u8981\u8fd4\u56de\u7684\u6570\u636e\u6761\u6570\u3002\u4f8b\u5982\uff1a db.collection.find().skip(10).limit(5); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u8df3\u8fc7\u524d10\u6761\u6570\u636e\uff0c\u5e76\u8fd4\u56de\u63a5\u4e0b\u6765\u76845\u6761\u6570\u636e\u3002 aggregate()\u7ba1\u9053 aggregate()\u7ba1\u9053\u63d0\u4f9b\u66f4\u7075\u6d3b\u7684\u5206\u9875\u9009\u9879\uff0c\u53ef\u4ee5\u4e0e\u5176\u4ed6\u805a\u5408\u64cd\u4f5c\u7ed3\u5408\u4f7f\u7528\u3002\u4f8b\u5982\uff1a db.collection.aggregate([ { $skip: 10 }, { $limit: 5 } ]); \u767b\u5f55\u540e\u590d\u5236 \u6e38\u6807 \u6e38\u6807\u5141\u8bb8\u4ee5\u8fed\u4ee3\u65b9\u5f0f\u8bbf\u95ee\u67e5\u8be2\u7ed3\u679c\uff0c\u5e76\u6309\u9700\u83b7\u53d6\u6570\u636e\u3002\u6e38\u6807\u652f\u6301\u5206\u9875\uff0c\u5982\u4e0b\u6240\u793a\uff1a cursor.skip(10).limit(5); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u5206\u9875\u67e5\u8be2\u7684\u6ce8\u610f\u4e8b\u9879 \u786e\u4fdd\u4f7f\u7528\u9002\u5f53\u7684\u7d22\u5f15\uff0c\u4ee5\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u3002 \u5982\u679c\u6570\u636e\u96c6\u5f88\u5927\uff0c\u8bf7\u8003\u8651\u4f7f\u7528\u6e38\u6807\u6216aggregate()\u7ba1\u9053\u8fdb\u884c\u5206\u9875\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u6027\u8fd4\u56de\u6240\u6709\u6570\u636e\u3002 \u5bf9\u4e8e\u901f\u5ea6\u81f3\u5173\u91cd\u8981\u7684\u5e94\u7528\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Mongodb Atlas\u641c\u7d22\u8fde\u63a5\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u5feb\u7684\u5206\u9875\u529f\u80fd\u3002 \u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u67e5\u8be2\u5206\u9875\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5556","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5556"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5556\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}