{"id":177761,"date":"2013-04-24T03:02:03","date_gmt":"2013-04-23T23:02:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=177761"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=177761","title":{"rendered":"<span class=\"post_title\">MongoDB: \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0439 \u0434\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u0438? \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043e\u0431\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/span>"},"content":{"rendered":"<div class=\"content html_format\">\n<h4>\u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h4>\n<p>  \u0411\u044b\u0432\u0430\u044e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u043c\u0435\u044e\u0442 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u0435\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043d\u0438\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">{     _id: 123,     firstName: &quot;John&quot;,     lastName: &quot;Smith&quot;,     age: 25,     height: 6.0,     dob: Date,     eyes: &quot;blue&quot;,     sign: &quot;Capricorn&quot;,     ... } <\/code><\/pre>\n<p>  \u041f\u043e \u0442\u0430\u043a\u0438\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043b\u044e\u0434\u0435\u0439 \u043f\u043e \u0446\u0432\u0435\u0442\u0443 \u0433\u043b\u0430\u0437, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u043e\u0441\u0442\u0430, \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \u0438 \u043f\u043e \u043f\u0440\u043e\u0447\u0438\u043c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u043c. \u0410 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043f\u043e\u043b\u0435\u0439, \u0438\u043b\u0438 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b, \u0438\u043b\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u043b\u0435\u0439? \u041a\u0430\u043a \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0431\u044b\u0441\u0442\u0440\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438\u0445 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u0442.\u043a \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u0440\u043e\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. <a name=\"habracut\"><\/a><\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 #1: \u0421\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u0438\u043c\u0435\u043d\u0430\u043c \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u043f\u043e\u043b\u0435\u0439<\/h4>\n<p>  \u0421\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u0445\u0435\u043c\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">{     _id: 123,     props: [     { n: &quot;firstName&quot;, v: &quot;John&quot;},     { n: &quot;lastName&quot;, v: &quot;Smith&quot;},     { n: &quot;age&quot;, v: 25},     ...     ] } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043f\u0438\u0441\u043a\u0430. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0438\u0437 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 (<code>prop0<\/code> <code>through<\/code> <code>prop9<\/code>) \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0442 <code>0<\/code> \u0434\u043e <code>1000<\/code>.<\/p>\n<pre><code class=\"javascript\">&gt; for (var i = 0; i &lt; 5000000; ++i) { var arr = []; for (var j = 0; j &lt; 10; ++j) { arr.push({n: &quot;prop&quot; + j, v: Math.floor(Math.random() * 1000) }) }; db.generic.insert({props: arr}) } &gt; db.generic.findOne() {   &quot;_id&quot;: ObjectId(&quot;515dd3b4f0bd676b816aa9b0&quot;),   &quot;props&quot;: [     {       &quot;n&quot;: &quot;prop0&quot;,       &quot;v&quot;: 40     },     {       &quot;n&quot;: &quot;prop1&quot;,       &quot;v&quot;: 198     }, ...     {       &quot;n&quot;: &quot;prop9&quot;,       &quot;v&quot;: 652     }   ] } &gt; db.generic.ensureIndex({&quot;props.n&quot;: 1, &quot;props.v&quot;: 1}) &gt; db.generic.stats() {   &quot;ns&quot;: &quot;test.generic&quot;,   &quot;count&quot;: 5020473,   &quot;size&quot;: 1847534064,   &quot;avgObjSize&quot;: 368,   &quot;storageSize&quot;: 2600636416,   &quot;numExtents&quot;: 19,   &quot;nindexes&quot;: 2,   &quot;lastExtentSize&quot;: 680280064,   &quot;paddingFactor&quot;: 1,   &quot;systemFlags&quot;: 1,   &quot;userFlags&quot;: 0,   &quot;totalIndexSize&quot;: 1785352240,   &quot;indexSizes&quot;: {     &quot;_id_&quot;: 162898624,     &quot;props.n_1_props.v_1&quot;: 1622453616   },   &quot;ok&quot;: 1 } <\/code><\/pre>\n<p>  \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0440\u0430\u0432\u0435\u043d 1.6 \u0413\u0431 \u0442.\u043a \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438 \u0438\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u0442\u0430\u043a \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 <code>prop1<\/code> \u0440\u0430\u0432\u0435\u043d <code>0<\/code>:<\/p>\n<pre><code class=\"javascript\">&gt; db.generic.findOne({&quot;props.n&quot;: &quot;prop1&quot;, &quot;props.v&quot;: 0}) {   &quot;_id&quot;: ObjectId(&quot;515dd4298bff7c34610f6ae8&quot;),   &quot;props&quot;: [     {       &quot;n&quot;: &quot;prop0&quot;,       &quot;v&quot;: 788     },     {       &quot;n&quot;: &quot;prop1&quot;,       &quot;v&quot;: 0     }, ...     {       &quot;n&quot;: &quot;prop9&quot;,       &quot;v&quot;: 788     }   ] } &gt; db.generic.find({&quot;props.n&quot;: &quot;prop1&quot;, &quot;props.v&quot;: 0}).explain() {   &quot;cursor&quot;: &quot;BtreeCursor props.n_1_props.v_1&quot;,   &quot;isMultiKey&quot;: true,   &quot;n&quot;: 49822,   &quot;nscannedObjects&quot;: 5020473,   &quot;nscanned&quot;: 5020473,   &quot;nscannedObjectsAllPlans&quot;: 5020473,   &quot;nscannedAllPlans&quot;: 5020473,   &quot;scanAndOrder&quot;: false,   &quot;indexOnly&quot;: false,   &quot;nYields&quot;: 0,   &quot;nChunkSkips&quot;: 0,   &quot;millis&quot;: 252028,   &quot;indexBounds&quot;: {     &quot;props.n&quot;: [       [         &quot;prop1&quot;,         &quot;prop1&quot;       ]     ],     &quot;props.v&quot;: [       [         {           &quot;$minElement&quot;: 1         },         {           &quot;$maxElement&quot;: 1         }       ]     ]   },   &quot;server&quot;: &quot;agmac.local:27017&quot; } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u0434\u0430\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430: \u043d\u0430\u0439\u0434\u0435\u043d\u043e ~50,000 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0437\u0430 252 \u0441\u0435\u043a\u0443\u043d\u0434\u044b. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 <code>n=prop1<\/code> \u0438 <code>v=0<\/code> \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u043e\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0435 \u043a\u0430\u043a \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e <code>n=prop1<\/code>, \u0442\u0430\u043a \u0438 <code>v=0<\/code> \u043f\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0442\u043e \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c. \u041c\u043e\u0436\u043d\u043e \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c <code>$elemMatch<\/code>:<\/p>\n<pre><code class=\"javascript\">&gt; db.generic.findOne({&quot;props&quot;: { $elemMatch: {n: &quot;prop1&quot;, v: 0} }}) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441 \u0438 \u043a\u0430\u043a \u0434\u043e\u043b\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 MongoDB v2.2:<\/p>\n<pre><code class=\"javascript\">&gt; db.generic.find({&quot;props&quot;: { $elemMatch: {n: &quot;prop1&quot;, v: 0} }}).explain() {   &quot;cursor&quot;: &quot;BtreeCursor props.n_1_props.v_1&quot;,   &quot;isMultiKey&quot;: true,   &quot;n&quot;: 5024,   &quot;nscannedObjects&quot;: 5020473,   &quot;nscanned&quot;: 5020473,   &quot;nscannedObjectsAllPlans&quot;: 5020473,   &quot;nscannedAllPlans&quot;: 5020473,   &quot;scanAndOrder&quot;: false,   &quot;indexOnly&quot;: false,   &quot;nYields&quot;: 0,   &quot;nChunkSkips&quot;: 0,   &quot;millis&quot;: 278784,   &quot;indexBounds&quot;: {     &quot;props.n&quot;: [       [         &quot;prop1&quot;,         &quot;prop1&quot;       ]     ],     &quot;props.v&quot;: [       [         {           &quot;$minElement&quot;: 1         },         {           &quot;$maxElement&quot;: 1         }       ]     ]   },   &quot;server&quot;: &quot;agmac.local:27017&quot; } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0432\u0435\u0440\u043d\u0443\u043b 5024 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430, \u043d\u043e \u0432\u0441\u0451 \u0435\u0449\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e! \u0418\u0437 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>explain<\/code> \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0447\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u044f <code>v<\/code> \u0432\u0441\u0451 \u0435\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>$elemMatch<\/code> \u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0439 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0435 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0442.\u043a \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e \u0431\u044b \u043a \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 MongoDB \u0441\u0434\u0435\u043b\u0430\u043b\u0430 \u0432\u044b\u0431\u043e\u0440 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f B-Tree \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 (\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>$elemMatch<\/code>). \u041d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 <code>$elemMatch<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e? \u0412\u0438\u043d\u043e\u0439 \u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b \u0431\u0430\u0433 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d <a href=\"https:\/\/jira.mongodb.org\/browse\/SERVER-3104\">SERVER-3104<\/a> \u0432 MongoDB v2.4. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438:<\/p>\n<pre><code class=\"javascript\">&gt; db.generic.find({&quot;props&quot;: { $elemMatch: {n: &quot;prop1&quot;, v: 0} }}).explain() {   &quot;cursor&quot;: &quot;BtreeCursor props.n_1_props.v_1&quot;,   &quot;isMultiKey&quot;: true,   &quot;n&quot;: 5024,   &quot;nscannedObjects&quot;: 5024,   &quot;nscanned&quot;: 5024,   &quot;nscannedObjectsAllPlans&quot;: 5024,   &quot;nscannedAllPlans&quot;: 5024,   &quot;scanAndOrder&quot;: false,   &quot;indexOnly&quot;: false,   &quot;nYields&quot;: 0,   &quot;nChunkSkips&quot;: 0,   &quot;millis&quot;: 21,   &quot;indexBounds&quot;: {     &quot;props.n&quot;: [       [         &quot;prop1&quot;,         &quot;prop1&quot;       ]     ],     &quot;props.v&quot;: [       [         0,         0       ]     ]   },   &quot;server&quot;: &quot;agmac.local:27017&quot; } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u0437\u0430 21 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0443!<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 #2: \u041e\u0434\u0438\u043d \u043e\u0431\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/h4>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u044d\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>property: value<\/code>. \u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 MongoDB \u0432\u0435\u0440\u0441\u0438\u0438 v2.2 \u0438 v2.4. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"javascript\">&gt; for (var i = 0; i &lt; 5000000; ++i) { var arr = []; for (var j = 0; j &lt; 10; ++j) { var doc = {}; doc[&quot;prop&quot; + j] =  Math.floor(Math.random() * 1000); arr.push(doc) }) }; db.generic2.insert({props: arr}) } &gt; db.generic2.findOne() {   &quot;_id&quot;: ObjectId(&quot;515e5e6a71b0722678929760&quot;),   &quot;props&quot;: [     {       &quot;prop0&quot;: 881     },     {       &quot;prop1&quot;: 47     }, ...     {       &quot;prop9&quot;: 717     }   ] } <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441:<\/p>\n<pre><code class=\"javascript\">&gt; db.generic2.ensureIndex({props: 1}) &gt; db.generic2.stats() {   &quot;ns&quot;: &quot;test.generic2&quot;,   &quot;count&quot;: 5000000,   &quot;size&quot;: 1360000032,   &quot;avgObjSize&quot;: 272.0000064,   &quot;storageSize&quot;: 1499676672,   &quot;numExtents&quot;: 19,   &quot;nindexes&quot;: 2,   &quot;lastExtentSize&quot;: 393670656,   &quot;paddingFactor&quot;: 1,   &quot;systemFlags&quot;: 1,   &quot;userFlags&quot;: 0,   &quot;totalIndexSize&quot;: 2384023488,   &quot;indexSizes&quot;: {     &quot;_id_&quot;: 162269072,     &quot;props_1&quot;: 2221754416   },   &quot;ok&quot;: 1 } <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0432 ~2.2 \u0413\u0431 \u0447\u0442\u043e \u043d\u0430 40% \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 #1 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e BSON \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0435\u0431\u044f \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0435 \u043a\u0430\u043a BLOB&#8217;\u044b. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"javascript\">&gt; db.generic2.find({&quot;props&quot;: {&quot;prop1&quot;: 0} }).explain() {   &quot;cursor&quot;: &quot;BtreeCursor props_1&quot;,   &quot;isMultiKey&quot;: true,   &quot;n&quot;: 4958,   &quot;nscannedObjects&quot;: 4958,   &quot;nscanned&quot;: 4958,   &quot;nscannedObjectsAllPlans&quot;: 4958,   &quot;nscannedAllPlans&quot;: 4958,   &quot;scanAndOrder&quot;: false,   &quot;indexOnly&quot;: false,   &quot;nYields&quot;: 0,   &quot;nChunkSkips&quot;: 0,   &quot;millis&quot;: 15,   &quot;indexBounds&quot;: {     &quot;props&quot;: [       [         {           &quot;prop1&quot;: 0         },         {           &quot;prop1&quot;: 0         }       ]     ]   },   &quot;server&quot;: &quot;agmac.local:27017&quot; } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u0437\u0430 15 \u043c\u0441 \u0447\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f! \u041d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u043f\u0440\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0434\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u0433\u0434\u0435 <code>prop1<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u0435\u043d \u043e\u0442 <code>0<\/code> \u0434\u043e <code>9<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"javascript\">&gt; db.generic2.find({&quot;props&quot;: { $gte: {&quot;prop1&quot;: 0}, $lte: {&quot;prop1&quot;: 9} }) <\/code><\/pre>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u044f \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435, \u0442\u043e \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u0442.\u043a \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 BLOB&#8217;\u043e\u0432).<br \/>  \u0422\u0430\u043a \u0436\u0435 \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435: \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 #1 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 <code>props.v<\/code> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0441\u0435\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043c\u0435\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>10<\/code>. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 #2 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442.<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0447\u0442\u043e MongoDB v2.4 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0438\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u00abBig Data\u00bb \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432.        \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/177761\/\"> http:\/\/habrahabr.ru\/post\/177761\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">\n<h4>\u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h4>\n<p>  \u0411\u044b\u0432\u0430\u044e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u043c\u0435\u044e\u0442 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u0435\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043d\u0438\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">{     _id: 123,     firstName: &quot;John&quot;,     lastName: &quot;Smith&quot;,     age: 25,     height: 6.0,     dob: Date,     eyes: &quot;blue&quot;,     sign: &quot;Capricorn&quot;,     ... } <\/code><\/pre>\n<p>  \u041f\u043e \u0442\u0430\u043a\u0438\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043b\u044e\u0434\u0435\u0439 \u043f\u043e \u0446\u0432\u0435\u0442\u0443 \u0433\u043b\u0430\u0437, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u043e\u0441\u0442\u0430, \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \u0438 \u043f\u043e \u043f\u0440\u043e\u0447\u0438\u043c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u043c. \u0410 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043f\u043e\u043b\u0435\u0439, \u0438\u043b\u0438 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b, \u0438\u043b\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u043b\u0435\u0439? \u041a\u0430\u043a \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0431\u044b\u0441\u0442\u0440\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438\u0445 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u0442.\u043a \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u0440\u043e\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-177761","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/177761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=177761"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/177761\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=177761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=177761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=177761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}