{"id":21552,"date":"2024-01-02T11:22:21","date_gmt":"2024-01-02T11:22:21","guid":{"rendered":"https:\/\/server.hk\/blog\/21552\/"},"modified":"2024-11-14T10:30:52","modified_gmt":"2024-11-14T02:30:52","slug":"mongodb-glossary-limit","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21552\/","title":{"rendered":"MongoDB \u8a5e\u5f59\u8868 &#8211; \u9650\u5236"},"content":{"rendered":"<h1 id=\"mongodb-glossary-limit-FkyOnJlECm\">MongoDB \u8a5e\u5f59\u8868 &#8211; \u9650\u5236<\/h1>\n<p>\u5728 MongoDB \u4e2d\uff0c<strong>\u9650\u5236<\/strong>\u662f\u4e00\u500b\u67e5\u8a62\u4fee\u98fe\u7b26\uff0c\u7528\u65bc\u9650\u5236\u67e5\u8a62\u7d50\u679c\u4e2d\u8fd4\u56de\u7684\u6587\u6a94\u6578\u91cf\u3002\u5b83\u5141\u8a31\u60a8\u63a7\u5236\u7d50\u679c\u96c6\u7684\u5927\u5c0f\uff0c\u4e26\u901a\u904e\u6e1b\u5c11\u901a\u904e\u7db2\u7d61\u50b3\u8f38\u7684\u6578\u64da\u91cf\u4f86\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002<\/p>\n<h2 id=\"how-does-the-limit-work-FkyOnJlECm\">\u9650\u5236\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff1f<\/h2>\n<p><strong>\u9650\u5236<\/strong>\u4fee\u98fe\u7b26\u8207 <code>find()<\/code> \u65b9\u6cd5\u4e00\u8d77\u4f7f\u7528\uff0c\u7528\u65bc\u6307\u5b9a\u8981\u8fd4\u56de\u7684\u6700\u5927\u6587\u6a94\u6578\u91cf\u3002\u5b83\u63a5\u53d7\u4e00\u500b\u53c3\u6578\uff0c\u5373\u8981\u5305\u542b\u5728\u7d50\u679c\u96c6\u4e2d\u7684\u6587\u6a94\u6578\u91cf\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8003\u616e\u4ee5\u4e0b\u67e5\u8a62\uff1a<\/p>\n<pre><code>db.collection.find().limit(10)<\/code><\/pre>\n<p>\u9019\u500b\u67e5\u8a62\u5c07\u8fd4\u56de\u6700\u591a 10 \u500b\u6587\u6a94\u4f86\u81ea <code>collection<\/code>\u3002\u5982\u679c\u96c6\u5408\u4e2d\u7684\u6587\u6a94\u5c11\u65bc 10 \u500b\uff0c\u5247\u6703\u8fd4\u56de\u6240\u6709\u6587\u6a94\u3002<\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c<strong>\u9650\u5236<\/strong>\u4fee\u98fe\u7b26\u6703\u5f71\u97ff\u8fd4\u56de\u6587\u6a94\u7684\u9806\u5e8f\u3002\u9ed8\u8a8d\u60c5\u6cc1\u4e0b\uff0cMongoDB \u6703\u6309\u7167\u6587\u6a94\u5728\u96c6\u5408\u4e2d\u51fa\u73fe\u7684\u9806\u5e8f\u8fd4\u56de\u6587\u6a94\u3002\u7136\u800c\uff0c\u7576\u61c9\u7528<strong>\u9650\u5236<\/strong>\u6642\uff0c\u70ba\u4e86\u512a\u5316\u6027\u80fd\uff0c\u9806\u5e8f\u53ef\u80fd\u6703\u6539\u8b8a\u3002<\/p>\n<h2 id=\"use-cases-for-limit-FkyOnJlECm\">\u9650\u5236\u7684\u4f7f\u7528\u6848\u4f8b<\/h2>\n<p><strong>\u9650\u5236<\/strong>\u4fee\u98fe\u7b26\u5728\u60a8\u53ea\u9700\u8981\u96c6\u5408\u4e2d\u7684\u4e00\u90e8\u5206\u6587\u6a94\u7684\u60c5\u6cc1\u4e0b\u7279\u5225\u6709\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u4f7f\u7528\u6848\u4f8b\uff1a<\/p>\n<h3 id=\"pagination-FkyOnJlECm\">\u5206\u9801<\/h3>\n<p>\u5728\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u4e2d\u5be6\u73fe\u5206\u9801\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528 <strong>\u9650\u5236<\/strong> \u4fee\u98fe\u7b26\u4f86\u63a7\u5236\u6bcf\u9801\u986f\u793a\u7684\u6587\u6a94\u6578\u91cf\u3002\u901a\u904e\u5c07<strong>\u9650\u5236<\/strong>\u8207 <code>skip()<\/code> \u65b9\u6cd5\u7d50\u5408\u4f7f\u7528\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5730\u5728\u5927\u578b\u7d50\u679c\u96c6\u4e2d\u5c0e\u822a\u3002<\/p>\n<h3 id=\"performance-optimization-FkyOnJlECm\">\u6027\u80fd\u512a\u5316<\/h3>\n<p>\u901a\u904e\u9650\u5236\u67e5\u8a62\u4e2d\u8fd4\u56de\u7684\u6587\u6a94\u6578\u91cf\uff0c\u60a8\u53ef\u4ee5\u6e1b\u5c11\u901a\u904e\u7db2\u7d61\u50b3\u8f38\u7684\u6578\u64da\u91cf\uff0c\u5f9e\u800c\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002\u9019\u5728\u8655\u7406\u5927\u578b\u96c6\u5408\u6216\u6162\u901f\u7db2\u7d61\u9023\u63a5\u6642\u5c24\u5176\u6709\u5229\u3002<\/p>\n<h3 id=\"testing-and-debugging-FkyOnJlECm\">\u6e2c\u8a66\u548c\u8abf\u8a66<\/h3>\n<p>\u5728\u958b\u767c\u904e\u7a0b\u4e2d\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u9650\u5236\u8fd4\u56de\u7684\u6587\u6a94\u6578\u91cf\uff0c\u4ee5\u5feb\u901f\u6e2c\u8a66\u6216\u8abf\u8a66\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u3002<strong>\u9650\u5236<\/strong>\u4fee\u98fe\u7b26\u5141\u8a31\u60a8\u5c08\u6ce8\u65bc\u8f03\u5c0f\u7684\u6578\u64da\u5b50\u96c6\uff0c\u5f9e\u800c\u66f4\u5bb9\u6613\u8b58\u5225\u548c\u4fee\u5fa9\u554f\u984c\u3002<\/p>\n<h2 id=\"conclusion-FkyOnJlECm\">\u7d50\u8ad6<\/h2>\n<p>MongoDB \u4e2d\u7684 <strong>\u9650\u5236<\/strong> \u4fee\u98fe\u7b26\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u7528\u65bc\u63a7\u5236\u67e5\u8a62\u7d50\u679c\u7684\u5927\u5c0f\u3002\u901a\u904e\u6307\u5b9a\u8981\u8fd4\u56de\u7684\u6700\u5927\u6587\u6a94\u6578\u91cf\uff0c\u60a8\u53ef\u4ee5\u512a\u5316\u6027\u80fd\u3001\u5be6\u73fe\u5206\u9801\u4e26\u7c21\u5316\u6e2c\u8a66\u548c\u8abf\u8a66\u3002\u6709\u6548\u5730\u4f7f\u7528<strong>\u9650\u5236<\/strong>\u4fee\u98fe\u7b26\u53ef\u4ee5\u5927\u5927\u589e\u5f37\u60a8\u5728 MongoDB \u4e2d\u7684\u67e5\u8a62\u80fd\u529b\u3002<\/p>\n<p>\u6b32\u4e86\u89e3\u66f4\u591a\u6709\u95dc VPS \u4e3b\u6a5f\u89e3\u6c7a\u65b9\u6848\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MongoDB \u8a5e\u5f59\u8868 &#038;#82&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-21552","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=21552"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21552\/revisions"}],"predecessor-version":[{"id":23898,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21552\/revisions\/23898"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}