{"id":259318,"date":"2015-06-15T13:29:02","date_gmt":"2015-06-15T09:29:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=259318"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=259318","title":{"rendered":"\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f MongoDB \u0432 e-commerce (\u0447\u0430\u0441\u0442\u044c 2)"},"content":{"rendered":"<p>     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/e36\/58a\/ca6\/e3658aca69ab496895f5bc53c7357632.jpeg\"\/><\/p>\n<p>  <a href=\"http:\/\/habrahabr.ru\/post\/259219\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a> <br \/>  \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u043e\u0441\u044c \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c. \u042d\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 <code>aggregation framework<\/code> \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0442\u0440\u0435\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 <a href=\"http:\/\/docs.mongodb.org\/ecosystem\/#use-cases\">\u044d\u043a\u043e\u0441\u0438\u0442\u0435\u043c\u0430<\/a> \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0441\u043e \u0441\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043a <code>MongoDB<\/code>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u043a\u043e\u043c\u043c\u0435\u0440\u0446\u0438\u0438.<\/p>\n<p>  \u0421\u043b\u0443\u0447\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0442\u0430\u043c \u043d\u0430 \u0432\u043e\u0441\u0435\u043c\u044c \u0441\u0442\u0430\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0442\u0440\u0438 \u0433\u0440\u0443\u043f\u043f\u044b. \u041c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u0441\u0430\u043c\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0442\u0440\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 <code>e-commerce<\/code>.<\/p>\n<ol>\n<li><a href=\"#1\">\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 aggregation framework<\/a><\/li>\n<li><a href=\"#2\"> \u041a\u0430\u0442\u0430\u043b\u043e\u0433 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432<\/a><\/li>\n<li><a href=\"#3\"> \u041a\u043e\u0440\u0437\u0438\u043d\u0430 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c\u0438 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435 <\/a><\/li>\n<li><a href=\"#4\"> \u0418\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439<\/a><\/li>\n<\/ol>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h3><a name=\"1\"><\/a> <font color=\"green\"> \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 aggregation framework<\/font><\/h3>\n<p>  \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432 <code>aggregation framework<\/code> \u0435\u0441\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>$project<\/code> \u0438\u043b\u0438 <code>$group<\/code> \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0438 <code>pipeline<\/code>.<br \/>  \u041d\u043e \u0435\u0441\u0442\u044c \u0438 \u0442\u0430\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043a\u0430\u043a <code>$cond<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. <br \/>  <em><font color=\"blue\">$cond<\/font><font color=\"#008B8B\"> \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e if<\/font><\/em><br \/>  \u041f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.6<\/code> \u0438 \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u0444\u043e\u0440\u043c\u044b \u0437\u0430\u043f\u0438\u0441\u0438:  <\/p>\n<pre><code class=\"python\">{ $cond: { if: &lt;boolean-expression&gt;, then: &lt;true-case&gt;, else: &lt;false-case-&gt; } } \u0438\u043b\u0438 { $cond: [ &lt;boolean-expression&gt;, &lt;true-case&gt;, &lt;false-case&gt; ] } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b:  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc1&quot;, qty: 300 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;abc2&quot;, qty: 200 } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;xyz1&quot;, qty: 250 } <\/code><\/pre>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c <code>discount<\/code> \u0440\u0430\u0432\u043d\u044b\u043c <code>30<\/code>, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0435 <code>qty<\/code> \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e <code>250<\/code>, \u0438\u043d\u0430\u0447\u0435 <code>discount<\/code> \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d <code>20<\/code>  <\/p>\n<pre><code class=\"python\">db.test.aggregate( [ {        $project:{              item: 1,              discount: { $cond: { if: { $gte: [ &quot;$qty&quot;, 250 ] }, then: 30, else: 20 } }         } } ] ) <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc1&quot;, &quot;discount&quot; : 30 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;abc2&quot;, &quot;discount&quot; : 20 } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;xyz1&quot;, &quot;discount&quot; : 30 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$ifNull <\/font><font color=\"#008B8B\"> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u043e null<\/font><\/em><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044f \u043d\u0435\u0442, \u0442\u043e \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c.  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc1&quot;, description: &quot;product 1&quot;, qty: 300 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;abc2&quot;, description: null, qty: 200 } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;xyz1&quot;, qty: 250 } <\/code><\/pre>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>Unspecified<\/code> \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044f <code>description<\/code> \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043b\u0438 \u043e\u043d\u043e \u0440\u0430\u0432\u043d\u043e <code>null<\/code>.  <\/p>\n<pre><code class=\"python\">db.test.aggregate( [ {          $project: { item: 1, description: { $ifNull: [ &quot;$description&quot;, &quot;Unspecified&quot; ]}} } ] ) <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc1&quot;, &quot;description&quot; : &quot;product 1&quot; } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;abc2&quot;, &quot;description&quot; : &quot;Unspecified&quot; } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;xyz1&quot;, &quot;description&quot; : &quot;Unspecified&quot; } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$let <\/font><font color=\"#008B8B\"> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 <\/font><\/em><\/p>\n<p>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>$let<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u043a\u0430\u043a\u0438\u0435 \u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. <br \/>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, <code>total<\/code> \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u043c\u044b \u0434\u0432\u0443\u0445 \u043f\u043e\u043b\u0435\u0439 <code>price, tax<\/code>. \u0410 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>discounted<\/code> \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>cond<\/code>. <br \/>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 <code>total<\/code> \u0438 <code>discounted<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"python\">{ _id: 1, price: 10, tax: 0.50, applyDiscount: true } { _id: 2, price: 10, tax: 0.25, applyDiscount: false }  db.test.aggregate( [ {       $project: {          finalTotal: {             $let: {                vars: {                   total: { $add: [ '$price', '$tax' ] },                   discounted: { $cond: { if: '$applyDiscount', then: 0.9, else: 1 } }                },                in: { $multiply: [ &quot;$$total&quot;, &quot;$$discounted&quot; ] }             }          }       } }] )  { &quot;_id&quot; : 1, &quot;finalTotal&quot; : 9.450000000000001 } { &quot;_id&quot; : 2, &quot;finalTotal&quot; : 10.25 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$map <\/font><font color=\"#008B8B\"> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443<\/font><\/em><br \/>  \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u043a\u0430\u043a\u043e\u0435 \u043b\u0438\u0431\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>+2<\/code>.  <\/p>\n<pre><code class=\"python\">{ _id: 1, quizzes: [ 5, 6, 7 ] } { _id: 2, quizzes: [ ] }  db.grades.aggregate([{       $project:{            adjustedGrades: {$map: {input: &quot;$quizzes&quot;, as: &quot;grade&quot;, in: { $add: [ &quot;$$grade&quot;, 2 ] } } }       } }])  { &quot;_id&quot; : 1, &quot;adjustedGrades&quot; : [ 7, 8, 9 ] } { &quot;_id&quot; : 2, &quot;adjustedGrades&quot; : [ ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$setEquals <\/font><font color=\"#008B8B\"> \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u044b<\/font><\/em><\/p>\n<p>  \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0430 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>true<\/code> \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b.  <\/p>\n<table>\n<tr>\n<td> \u041f\u0440\u0438\u043c\u0435\u0440<\/td>\n<td>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <\/td>\n<\/tr>\n<tr>\n<td> { $setEquals: [ [ \u00aba\u00bb, \u00abb\u00bb, \u00aba\u00bb ], [ \u00abb\u00bb, \u00aba\u00bb ] ] }<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td> { $setEquals: [ [ \u00aba\u00bb, \u00abb\u00bb ], [ [ \u00aba\u00bb, \u00abb\u00bb ] ] ] } <\/td>\n<td>false<\/td>\n<\/tr>\n<\/table>\n<p>  <em><font color=\"blue\">$setIntersection <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043e\u0432\u043f\u0430\u0432\u0448\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b<\/font><\/em><br \/>  \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432. \u0415\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u043f\u0443\u0441\u0442\u043e\u0439 \u0438\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432.  <\/p>\n<table>\n<tr>\n<td> \u041f\u0440\u0438\u043c\u0435\u0440<\/td>\n<td>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <\/td>\n<\/tr>\n<tr>\n<td> { $setIntersection: [ [ \u00aba\u00bb, \u00abb\u00bb, \u00aba\u00bb ], [ \u00abb\u00bb, \u00aba\u00bb ] ] }<\/td>\n<td> [ \u00abb\u00bb, \u00aba\u00bb ]<\/td>\n<\/tr>\n<tr>\n<td>{ $setIntersection: [ [ \u00aba\u00bb, \u00abb\u00bb ], [ [ \u00aba\u00bb, \u00abb\u00bb ] ] ] } <\/td>\n<td> [ ]<\/td>\n<\/tr>\n<\/table>\n<p>  <em><font color=\"blue\">$setUnion <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432 \u043b\u044e\u0431\u043e\u043c \u0438\u0437 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/font><\/em><\/p>\n<p>  \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u043c \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435.  <\/p>\n<table>\n<tr>\n<td> \u041f\u0440\u0438\u043c\u0435\u0440<\/td>\n<td>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <\/td>\n<\/tr>\n<tr>\n<td>{ $setUnion: [ [ \u00aba\u00bb, \u00abb\u00bb, \u00aba\u00bb ], [ \u00abb\u00bb, \u00aba\u00bb ] ] } <\/td>\n<td> [ \u00abb\u00bb, \u00aba\u00bb ]<\/td>\n<\/tr>\n<tr>\n<td> { $setUnion: [ [ \u00aba\u00bb, \u00abb\u00bb ], [ [ \u00aba\u00bb, \u00abb\u00bb ] ] ] }<\/td>\n<td>[ [ \u00aba\u00bb, \u00abb\u00bb ], \u00abb\u00bb, \u00aba\u00bb ] <\/td>\n<\/tr>\n<\/table>\n<p>  <em><font color=\"blue\">$setDifference <\/font><font color=\"#008B8B\"> \u0442\u043e\u0436\u0435 \u0447\u0442\u043e setUnion \u043d\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 <\/font><\/em>  <\/p>\n<table>\n<tr>\n<td> \u041f\u0440\u0438\u043c\u0435\u0440<\/td>\n<td>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <\/td>\n<\/tr>\n<tr>\n<td>{ $setDifference: [ [ \u00aba\u00bb, \u00abb\u00bb, \u00aba\u00bb ], [ \u00abb\u00bb, \u00aba\u00bb ] ] } <\/td>\n<td>[ ]<\/td>\n<\/tr>\n<tr>\n<td> { $setDifference: [ [ \u00aba\u00bb, \u00abb\u00bb ], [ [ \u00aba\u00bb, \u00abb\u00bb ] ] ] }<\/td>\n<td>[ \u00aba\u00bb, \u00abb\u00bb ] <\/td>\n<\/tr>\n<\/table>\n<p>  <em><font color=\"blue\">$setIsSubset <\/font><font color=\"#008B8B\"> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430 \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/font><\/em><br \/>   \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 True, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0440\u0430\u0432\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u043c\u0443, \u0438 false \u0435\u0441\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.  <\/p>\n<table>\n<tr>\n<td> \u041f\u0440\u0438\u043c\u0435\u0440<\/td>\n<td>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <\/td>\n<\/tr>\n<tr>\n<td> { $setIsSubset: [ [ \u00aba\u00bb, \u00abb\u00bb, \u00aba\u00bb ], [ \u00abb\u00bb, \u00aba\u00bb ] ] }<\/td>\n<td>true <\/td>\n<\/tr>\n<tr>\n<td> { $setIsSubset: [ [ \u00aba\u00bb, \u00abb\u00bb ], [ [ \u00aba\u00bb, \u00abb\u00bb ] ] ] }<\/td>\n<td>false <\/td>\n<\/tr>\n<\/table>\n<p>  <em><font color=\"blue\">$anyElementTrue <\/font><\/em><br \/>  \u041e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0432\u0438\u0434\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 True, \u0435\u0441\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 True \u0438 false \u0435\u0441\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u041f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 false. \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442.  <\/p>\n<table>\n<tr>\n<td> \u041f\u0440\u0438\u043c\u0435\u0440<\/td>\n<td>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <\/td>\n<\/tr>\n<tr>\n<td> { $anyElementTrue: [ [ true, false ] ] }<\/td>\n<td> <\/td>\n<\/tr>\n<tr>\n<td> { $anyElementTrue: [ [ [ false ] ] ] }<\/td>\n<td> <\/td>\n<\/tr>\n<tr>\n<td> { $anyElementTrue: [ [ null, false, 0 ] ] }<\/td>\n<td> <\/td>\n<\/tr>\n<tr>\n<td> { $anyElementTrue: [ [ ] ] }<\/td>\n<td> <\/td>\n<\/tr>\n<\/table>\n<p>  <em><font color=\"blue\">$allElementsTrue <\/font><\/em><br \/>  \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 True, \u0435\u0441\u043b\u0438 \u043d\u0435 \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043d\u0435 \u0440\u0430\u0432\u0435\u043d false. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 false. \u041f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 True.  <\/p>\n<table>\n<tr>\n<td> \u041f\u0440\u0438\u043c\u0435\u0440<\/td>\n<td>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <\/td>\n<\/tr>\n<tr>\n<td> { $allElementsTrue: [ [ true, 1, \u00absomeString\u00bb ] ] }<\/td>\n<td> <\/td>\n<\/tr>\n<tr>\n<td> { $allElementsTrue: [ [ [ false ] ] ] }<\/td>\n<td> <\/td>\n<\/tr>\n<tr>\n<td> { $allElementsTrue: [ [ ] ] }<\/td>\n<td> <\/td>\n<\/tr>\n<tr>\n<td> { $allElementsTrue: [ [ null, false, 0 ] ] }<\/td>\n<td> <\/td>\n<\/tr>\n<\/table>\n<p>  <em><font color=\"blue\">$cmp <\/font><font color=\"#008B8B\"> \u2014 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/font><\/em><br \/>  \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442:  <\/p>\n<ul>\n<li>-1, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e.<\/li>\n<li> 1, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e.<\/li>\n<li> 0, \u0435\u0441\u043b\u0438 \u043e\u0431\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0432\u043d\u044b.<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc1&quot;, description: &quot;product 1&quot;, qty: 300 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;abc2&quot;, description: &quot;product 2&quot;, qty: 200 } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;xyz1&quot;, description: &quot;product 3&quot;, qty: 250 } <\/code><\/pre>\n<p>  C \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>$cmp<\/code> \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>qty<\/code> \u0441 <code>250<\/code>:<\/p>\n<pre><code class=\"python\">db.test.aggregate( [ {        $project:{ _id: 0, item: 1,qty: 1, cmpTo250: { $cmp: [ &quot;$qty&quot;, 250 ] } } } ] ) <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"python\">{ &quot;item&quot; : &quot;abc1&quot;, &quot;qty&quot; : 300, &quot;cmpTo250&quot; : 1 } { &quot;item&quot; : &quot;abc2&quot;, &quot;qty&quot; : 200, &quot;cmpTo250&quot; : -1 } { &quot;item&quot; : &quot;xyz1&quot;, &quot;qty&quot; : 250, &quot;cmpTo250&quot; : 0 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$add <\/font><font color=\"#008B8B\"> \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0435\u0442<\/font><\/em>  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc&quot;, &quot;price&quot; : 10, &quot;fee&quot; : 2 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;jkl&quot;, &quot;price&quot; : 20, &quot;fee&quot; : 1 }  db.test.aggregate([ { $project: { item: 1, total: { $add: [ &quot;$price&quot;, &quot;$fee&quot; ] } } }  ])  { &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc&quot;, &quot;total&quot; : 12 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;jkl&quot;, &quot;total&quot; : 21 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$subtract <\/font><font color=\"#008B8B\"> \u0432\u044b\u0447\u0438\u0442\u0430\u0435\u0442<\/font><\/em><br \/>  \u041c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0434\u0430\u0442 \u0432 \u043c\u0438\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445.  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc&quot;, &quot;price&quot; : 10, &quot;fee&quot; : 2, &quot;discount&quot; : 5 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;jkl&quot;, &quot;price&quot; : 20, &quot;fee&quot; : 1, &quot;discount&quot; : 2 }  db.test.aggregate( [ {        $project: { item: 1, total: { $subtract: [ { $add: [ &quot;$price&quot;, &quot;$fee&quot; ] }, &quot;$discount&quot; ] } }  } ] )  { &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc&quot;, &quot;total&quot; : 7 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;jkl&quot;, &quot;total&quot; : 19 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$multiply <\/font><font color=\"#008B8B\"> \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442 <\/font><\/em><\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc&quot;, &quot;price&quot; : 10, &quot;quantity&quot;: 2 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;jkl&quot;, &quot;price&quot; : 20, &quot;quantity&quot;: 1  }  db.test.aggregate([ { $project: { item: 1, total: { $multiply: [ &quot;$price&quot;, &quot;$quantity&quot; ] } } } ])  { &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc&quot;, &quot;total&quot; : 20 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;jkl&quot;,   &quot;total&quot; : 20 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$divide <\/font><font color=\"#008B8B\"> \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u0435\u043b\u0435\u043d\u0438\u044f <\/font><\/em>  <\/p>\n<pre><code class=\"python\"> { &quot;_id&quot; : 1, &quot;name&quot; : &quot;A&quot;, &quot;hours&quot; : 80, &quot;resources&quot; : 7 }, { &quot;_id&quot; : 2, &quot;name&quot; : &quot;B&quot;, &quot;hours&quot; : 40, &quot;resources&quot; : 4 }  db.test.aggregate([ { $project: { name: 1, workdays: { $divide: [ &quot;$hours&quot;, 8 ] } } } ])  { &quot;_id&quot; : 1, &quot;name&quot; : &quot;A&quot;, &quot;workdays&quot; : 10 } { &quot;_id&quot; : 2, &quot;name&quot; : &quot;B&quot;, &quot;workdays&quot; : 5 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$concat <\/font><font color=\"#008B8B\"> \u2014 \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044f \u0441\u0442\u0440\u043e\u043a<\/font><\/em>  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;ABC1&quot;, quarter: &quot;13Q1&quot;, &quot;description&quot; : &quot;product 1&quot; }  db.test.aggregate([ { $project: { itemDescription: { $concat: [ &quot;$item&quot;, &quot; - &quot;, &quot;$description&quot; ] } } } ])  { &quot;_id&quot; : 1, &quot;itemDescription&quot; : &quot;ABC1 - product 1&quot; } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$substr <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0443 <\/font><\/em><\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430. \u0418\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0443\u043b\u044f.<\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;ABC1&quot;, quarter: &quot;13Q1&quot;, &quot;description&quot; : &quot;product 1&quot; } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;ABC2&quot;, quarter: &quot;13Q4&quot;, &quot;description&quot; : &quot;product 2&quot; } db.inventory.aggregate([{     $project:{         item: 1,         yearSubstring: { $substr: [ &quot;$quarter&quot;, 0, 2 ] },         quarterSubtring: { $substr: [ &quot;$quarter&quot;, 2, -1 ] }      } }]) { &quot;_id&quot; : 1, &quot;item&quot; : &quot;ABC1&quot;, &quot;yearSubstring&quot; : &quot;13&quot;, &quot;quarterSubtring&quot; : &quot;Q1&quot; } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;ABC2&quot;, &quot;yearSubstring&quot; : &quot;13&quot;, &quot;quarterSubtring&quot; : &quot;Q4&quot; } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$toLower <\/font><font color=\"#008B8B\"> \u2014 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 <\/font><\/em>  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;ABC1&quot;, quarter: &quot;13Q1&quot;, &quot;description&quot; : &quot;PRODUCT 1&quot; }  db.test.aggregate([{     $project:{  item: { $toLower: &quot;$item&quot; }, description: { $toLower: &quot;$description&quot; }} }])  { &quot;_id&quot; : 1, &quot;item&quot; : &quot;abc1&quot;, &quot;description&quot; : &quot;product 1&quot; } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$toUpper <\/font><font color=\"#008B8B\"> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432 \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440<\/font><\/em><\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 2, &quot;item&quot; : &quot;abc2&quot;, quarter: &quot;13Q4&quot;, &quot;description&quot; : &quot;Product 2&quot; }  db.inventory.aggregate( [ {        $project:{ item: { $toUpper: &quot;$item&quot; }, description: { $toUpper: &quot;$description&quot; } } } ] )  { &quot;_id&quot; : 2, &quot;item&quot; : &quot;ABC2&quot;, &quot;description&quot; : &quot;PRODUCT 2&quot; } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$strcasecmp <\/font><font color=\"#008B8B\"> \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 <\/font><\/em><br \/>  \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442:  <\/p>\n<ul>\n<li> 1, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u201c\u0431\u043e\u043b\u044c\u0448\u0435\u201d \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/li>\n<li> 0, \u0435\u0441\u043b\u0438 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0440\u0430\u0432\u043d\u044b.<\/li>\n<li>-1, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u201c\u043c\u0435\u043d\u044c\u0448\u0435\u201d \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/li>\n<\/ul>\n<p>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443.  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;ABC1&quot;, quarter: &quot;13Q1&quot;, &quot;description&quot; : &quot;product 1&quot; } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;ABC2&quot;, quarter: &quot;13Q4&quot;, &quot;description&quot; : &quot;product 2&quot; } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;XYZ1&quot;, quarter: &quot;14Q2&quot;, &quot;description&quot; : null }  db.inventory.aggregate([{        $project:{ item: 1, comparisonResult: { $strcasecmp: [ &quot;$quarter&quot;, &quot;13q4&quot; ] } } }])  { &quot;_id&quot; : 1, &quot;item&quot; : &quot;ABC1&quot;, &quot;comparisonResult&quot; : -1 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;ABC2&quot;, &quot;comparisonResult&quot; : 0 } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;XYZ1&quot;, &quot;comparisonResult&quot; : 1 } <\/code><\/pre>\n<h5>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0430\u0442\u0430\u043c\u0438<\/h5>\n<p>  <em><font color=\"blue\">$dayOfYear <\/font><font color=\"#008B8B\"> \u0434\u0435\u043d\u044c \u0432 \u0433\u043e\u0434\u0443 \u043f\u043e \u0441\u0447\u0435\u0442\u0443<\/font><\/em><br \/>  <em><font color=\"blue\">$dayOfMonth <\/font><font color=\"#008B8B\"> \u0434\u0435\u043d\u044c \u0432 \u043c\u0435\u0441\u044f\u0446\u0435 \u043f\u043e \u0441\u0447\u0435\u0442\u0443<\/font><\/em><br \/>  <em><font color=\"blue\">$dayOfWeek <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0435\u043d\u044c \u043d\u0435\u0434\u0435\u043b\u0438 \u043f\u043e \u0441\u0447\u0435\u0442\u0443, 1 (\u0441\u0443\u0431\u0431\u043e\u0442\u0430) \u2014 7 (\u0432\u043e\u0441\u043a\u0440\u0435\u0441\u0435\u043d\u044c\u0435).<\/font><\/em><br \/>  <em><font color=\"blue\">$year <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0433\u043e\u0434 <\/font><\/em><br \/>  <em><font color=\"blue\">$month <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0435\u0441\u044f\u0446 \u043f\u043e \u0441\u0447\u0435\u0442\u0443<\/font><\/em><br \/>  <em><font color=\"blue\">$week <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 \u043d\u0435\u0434\u0435\u043b\u0438 \u0432 \u0433\u043e\u0434\u0443 \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e \u043e\u0442 0 \u0434\u043e 53<\/font><\/em><br \/>  <em><font color=\"blue\">$hour <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0447\u0430\u0441 \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u0436\u0434\u0443 0 \u0438 23<\/font><\/em><br \/>  <em><font color=\"blue\">$minute <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0438\u043d\u0443\u0442\u0443 \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u0436\u0434\u0443 0 \u0438 59<\/font><\/em><br \/>  <em><font color=\"blue\">$second <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u0436\u0434\u0443 0 \u0438 23<\/font><\/em><br \/>  <em><font color=\"blue\">$millisecond <\/font><font color=\"#008B8B\"> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0438\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u0436\u0434\u0443 0 \u0438 999<\/font><\/em><\/p>\n<p>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0435\u043d\u044c \u0433\u043e\u0434\u0430 \u0434\u043b\u044f \u0434\u0430\u0442\u044b \u0432 \u0432\u0438\u0434\u0435 \u0447\u0438\u0441\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 1 \u0438 366.<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f 1 \u044f\u043d\u0432\u0430\u0440\u044f \u0432\u0435\u0440\u043d\u0435\u0442 1.  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot;: 1, &quot;item&quot;: &quot;abc&quot;, &quot;date&quot; : ISODate(&quot;2014-01-01T08:15:39.736Z&quot;) } db.sales.aggregate( [ {     $project: {            year: { $year: &quot;$date&quot; },            month: { $month: &quot;$date&quot; },             day: { $dayOfMonth: &quot;$date&quot; },            hour: { $hour: &quot;$date&quot; },            minutes: { $minute: &quot;$date&quot; },            seconds: { $second: &quot;$date&quot; },            milliseconds: { $millisecond: &quot;$date&quot; },            dayOfYear: { $dayOfYear: &quot;$date&quot; },            dayOfWeek: { $dayOfWeek: &quot;$date&quot; },            week: { $week: &quot;$date&quot; }       } } ] )  {   &quot;_id&quot; : 1,    &quot;year&quot; : 2014,    &quot;month&quot; : 1,    &quot;day&quot; : 1,   &quot;hour&quot; : 8,   &quot;minutes&quot; : 15,   &quot;seconds&quot; : 39,   &quot;milliseconds&quot; : 736,   &quot;dayOfYear&quot; : 1,   &quot;dayOfWeek&quot; : 4,   &quot;week&quot; : 0 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$dateToString <\/font><font color=\"#008B8B\"> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443<\/font><\/em><\/p>\n<p>  \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 date \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u043c.  <\/p>\n<pre><code class=\"python\">{   &quot;_id&quot; : 1,   &quot;item&quot; : &quot;abc&quot;,   &quot;price&quot; : 10,   &quot;quantity&quot; : 2,   &quot;date&quot; : ISODate(&quot;2014-01-01T08:15:39.736Z&quot;) } db.test.aggregate( [ {        $project: {           yearMonthDay: { $dateToString: { format: &quot;%Y-%m-%d&quot;, date: &quot;$date&quot; } },           time: { $dateToString: { format: &quot;%H:%M:%S:%L&quot;, date: &quot;$date&quot; } }        } } ] ) { &quot;_id&quot; : 1, &quot;yearMonthDay&quot; : &quot;2014-01-01&quot;, &quot;time&quot; : &quot;08:15:39:736&quot; } <\/code><\/pre>\n<h3><a name=\"2\"><\/a> <font color=\"green\"> \u041a\u0430\u0442\u0430\u043b\u043e\u0433 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432<\/font><\/h3>\n<p>  \u042d\u0442\u0430 \u0433\u043b\u0430\u0432\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043a\u043e\u043c\u043c\u0435\u0440\u0446\u0438\u0438, \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>MongoDB<\/code>.<\/p>\n<p>  \u041a\u0430\u0442\u0430\u043b\u043e\u0433 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0438\u0434\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a.<br \/>  \u0414\u043b\u044f \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0448\u0430\u0442\u044c\u0441\u044f \u0432 <code>MongoDB<\/code>.<\/p>\n<h4><font color=\"blue\">SQL \u0438 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445<\/font><\/h4>\n<p>  <em><font color=\"blue\">Concrete Table Inheritance (\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432)<\/font><em>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u2014 \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432:<\/p>\n<pre><code class=\"sql\">CREATE TABLE `product_audio_album` (     `sku` char(8) NOT NULL,     ...     `artist` varchar(255) DEFAULT NULL,     `genre_0` varchar(255) DEFAULT NULL,     `genre_1` varchar(255) DEFAULT NULL,     ...,     PRIMARY KEY(`sku`)) ... CREATE TABLE `product_film` (     `sku` char(8) NOT NULL,     ...     `title` varchar(255) DEFAULT NULL,     `rating` char(8) DEFAULT NULL,     ...,     PRIMARY KEY(`sku`)) ... <\/code><\/pre>\n<p>  \u0423 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c\u044e.  <\/p>\n<ul>\n<li>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0432\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.<\/li>\n<li>\u042f\u0432\u043d\u0430\u044f \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.<\/li>\n<\/ul>\n<p>  <em><font color=\"blue\">Single Table Inheritance (\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0435\u0434\u0438\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439)<\/font><em>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u0442\u043e\u0432\u0430\u0440\u043e\u0432. \u0418 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u043d\u043e\u0432\u044b\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0432 \u043b\u044e\u0431\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0442\u0438\u043f\u0430\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432:<\/p>\n<pre><code class=\"sql\">CREATE TABLE `product` (     `sku` char(8) NOT NULL,     ...     `artist` varchar(255) DEFAULT NULL,     `genre_0` varchar(255) DEFAULT NULL,     `genre_1` varchar(255) DEFAULT NULL,     ...     `title` varchar(255) DEFAULT NULL,     `rating` char(8) DEFAULT NULL,     ...,     PRIMARY KEY(`sku`)) <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u043c \u0438 \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.<\/p>\n<p>  <em><font color=\"blue\">Multiple Table Inheritance (\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446)<\/font><em>\u0422\u0430\u043a\u0436\u0435 \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u00ab\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u00bb, \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0431\u0449\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>product<\/code> \u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 (\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0441\u0432\u043e\u044f) \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <code>SQL<\/code> \u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"sql\">CREATE TABLE `product` (     `sku` char(8) NOT NULL,     `title` varchar(255) DEFAULT NULL,     `description` varchar(255) DEFAULT NULL,     `price`, ...     PRIMARY KEY(`sku`))  CREATE TABLE `product_audio_album` (     `sku` char(8) NOT NULL,     ...     `artist` varchar(255) DEFAULT NULL,     `genre_0` varchar(255) DEFAULT NULL,     `genre_1` varchar(255) DEFAULT NULL,     ...,     PRIMARY KEY(`sku`),     FOREIGN KEY(`sku`) REFERENCES `product`(`sku`)) ... CREATE TABLE `product_film` (     `sku` char(8) NOT NULL,     ...     `title` varchar(255) DEFAULT NULL,     `rating` char(8) DEFAULT NULL,     ...,     PRIMARY KEY(`sku`),     FOREIGN KEY(`sku`) REFERENCES `product`(`sku`)) ... <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0447\u0435\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u043c \u0447\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438. \u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u00ab\u0434\u043e\u0440\u043e\u0433\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e\u00bb <code>JOIN<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0445\u0441\u044f \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0442\u043e\u0432\u0430\u0440\u0443.<\/p>\n<p>  <em><font color=\"blue\">\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/font><em>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u2014 \u044d\u0442\u043e \u0441\u0445\u0435\u043c\u0430 <code>entity-attribute-value<\/code>. \u0412 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u043e\u0439 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0442\u0440\u0435\u043c\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>entity_id<\/code>, <code>attribute_id<\/code>, <code>value<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0430\u0443\u0434\u0438\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439:  <\/p>\n<table>\n<tr>\n<td>Entity<\/td>\n<td>Attribute<\/td>\n<td>Value<\/td>\n<\/tr>\n<tr>\n<td>sku_00e8da9b<\/td>\n<td>type<\/td>\n<td>Audio Album<\/td>\n<\/tr>\n<tr>\n<td>sku_00e8da9b<\/td>\n<td>title<\/td>\n<td>A Love Supreme<\/td>\n<\/tr>\n<tr>\n<td>sku_00e8da9b<\/td>\n<td>&#8230;<\/td>\n<td>&#8230;<\/td>\n<\/tr>\n<tr>\n<td>sku_00e8da9b<\/td>\n<td>artist<\/td>\n<td>John Coltrane<\/td>\n<\/tr>\n<tr>\n<td>sku_00e8da9b<\/td>\n<td>genre<\/td>\n<td>Jazz<\/td>\n<\/tr>\n<tr>\n<td>sku_00e8da9b<\/td>\n<td>genre<\/td>\n<td>General<\/td>\n<\/tr>\n<tr>\n<td>&#8230;<\/td>\n<td>&#8230;<\/td>\n<td>&#8230;<\/td>\n<\/tr>\n<\/table>\n<p>  <\/em><\/p>\n<p>  \u042d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0430\u044f:<\/p>\n<p>  \u041b\u044e\u0431\u043e\u0439 \u0442\u043e\u0432\u0430\u0440 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432. \u041d\u043e\u0432\u044b\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0431\u0430\u0437\u0443.<\/p>\n<p>  \u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 <code>JOIN<\/code>, \u0447\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f <code>e-commerce<\/code> \u0441 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u043e\u043b\u043e\u043d\u043a\u0435 BLOB. \u0418 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0442\u0440\u0443\u0434\u043d\u043e\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<h4><font color=\"blue\">\u041d\u0435 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445<\/font><\/h4>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>mongodb<\/code> \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432 \u043f\u043b\u0430\u043d\u0435 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0432\u0438\u0434\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0418 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0439, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0443 \u0442\u043e\u0432\u0430\u0440\u0430 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 (\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b) \u0432 \u043e\u0434\u043d\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435.<\/p>\n<p>  \u0412 \u043a\u043e\u0440\u043d\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0431\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0443. \u0410 \u0443\u0436\u0435 \u0432 \u0441\u0443\u0431\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">{   sku: &quot;00e8da9b&quot;,   type: &quot;Audio Album&quot;,   title: &quot;A Love Supreme&quot;,   description: &quot;by John Coltrane&quot;,   asin: &quot;B0000A118M&quot;,    shipping: {     weight: 6,     dimensions: {       width: 10,       height: 10,       depth: 1     },   },    pricing: {     list: 1200,     retail: 1100,     savings: 100,     pct_savings: 8   },    details: {     title: &quot;A Love Supreme [Original Recording Reissued]&quot;,     artist: &quot;John Coltrane&quot;,     genre: [ &quot;Jazz&quot;, &quot;General&quot; ],         ...     tracks: [       &quot;A Love Supreme Part I: Acknowledgement&quot;,       &quot;A Love Supreme Part II - Resolution&quot;,       &quot;A Love Supreme, Part III: Pursuance&quot;,       &quot;A Love Supreme, Part IV-Psalm&quot;     ],   }, } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0444\u0438\u043b\u044c\u043c\u0430\u0445 <code> { type: &quot;Film&quot; }<\/code> \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0446\u0435\u043d\u0430, \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0430 \u0438 \u0442.\u0434. \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435. \u0410 \u0432\u043e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0441\u0443\u0431\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u0441\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">{   sku: &quot;00e8da9d&quot;,   type: &quot;Film&quot;,   ...,   asin: &quot;B000P0J0AQ&quot;,    shipping: { ... },    pricing: { ... },    details: {     title: &quot;The Matrix&quot;,     director: [ &quot;Andy Wachowski&quot;, &quot;Larry Wachowski&quot; ],     writer: [ &quot;Andy Wachowski&quot;, &quot;Larry Wachowski&quot; ],     ...,     aspect_ratio: &quot;1.66:1&quot;   }, } <\/code><\/pre>\n<p>  \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u2014 \u044d\u0442\u043e \u043f\u043e\u0438\u0441\u043a. \u041d\u0438\u0436\u0435 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f. \u0412\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u043d\u0430 <code>Python\/PyMongo<\/code>.<\/p>\n<p>  <em><font color=\"blue\">\u041d\u0430\u0439\u0442\u0438 \u0430\u043b\u044c\u0431\u043e\u043c\u044b \u043f\u043e \u0436\u0430\u043d\u0440\u0443 \u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0433\u043e\u0434\u0443 \u0432\u044b\u043f\u0443\u0441\u043a\u0430<\/font><\/em><br \/>  \u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u0442\u043e\u0432\u0430\u0440\u0430\u043c\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0436\u0430\u043d\u0440\u0443 \u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0445\u0440\u043e\u043d\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435:  <\/p>\n<pre><code class=\"python\">query = db.products.find({'type':'Audio Album',  'details.genre': 'jazz'}).sort([('details.issue_date', -1)]) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441, \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0438 \u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435:  <\/p>\n<pre><code class=\"python\">db.products.ensure_index([ ('type', 1), ('details.genre', 1), ('details.issue_date', -1)]) <\/code><\/pre>\n<p>  <em><font color=\"blue\">\u041d\u0430\u0439\u0442\u0438 \u0442\u043e\u0432\u0430\u0440\u044b, \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0443 \u0441\u043a\u0438\u0434\u043a\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f.<\/font><\/em><br \/>  \u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0430\u043b\u044c\u0431\u043e\u043c\u044b, \u0444\u0438\u043b\u044c\u043c\u044b \u0438 \u0442.\u0434.), \u0447\u0430\u0441\u0442\u043e \u043d\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u0446\u0435\u043d\u043e\u0432\u043e\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435.<\/p>\n<p>  \u041d\u0430\u0439\u0434\u0435\u043c \u0442\u043e\u0432\u0430\u0440\u044b \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0441\u043a\u0438\u0434\u043a\u0430, \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u0441 \u0446\u0435\u043d\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0435\u0441\u0442\u044c \u0432\u043e \u0432\u0441\u0435\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445.<\/p>\n<pre><code class=\"python\">query = db.products.find( { 'pricing.pct_savings': {'$gt': 25 }).sort([('pricing.pct_savings', -1)]) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u043f\u043e\u043b\u044e <code>pricing.pct_savings<\/code>:<\/p>\n<pre><code class=\"python\">db.products.ensure_index('pricing.pct_savings') <\/code><\/pre>\n<p>  <code>MongoDB<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043a\u0430\u043a \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f \u0442\u0430\u043a \u0438 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <em><font color=\"blue\">\u041d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0444\u0438\u043b\u044c\u043c\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0433\u0440\u0430\u043b\u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0430\u043a\u0442\u0435\u0440\u044b<\/font><\/em><br \/>  \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0438\u043f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 <code>&quot;Film&quot;<\/code> \u0438 \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>{ 'actor': 'Keanu Reeves' }<\/code>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0434\u0430\u0442\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">query = db.products.find({'type': 'Film', 'details.actor': 'Keanu Reeves'}).sort([('details.issue_date', -1)]) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441:<\/p>\n<pre><code class=\"python\">db.products.ensure_index([ ('type', 1), ('details.actor', 1), ('details.issue_date', -1)]) <\/code><\/pre>\n<p>  \u0418\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043b\u044f <code>type<\/code> \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0435\u0441\u0442\u044c \u0432\u043e \u0432\u0441\u0435\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0443\u0436\u0435 \u0438\u0434\u0435\u0442 \u043f\u043e \u043f\u043e\u043b\u044e <code>details.actor<\/code> \u044d\u0442\u0438\u043c \u043c\u044b \u043a\u0430\u043a \u0431\u044b \u0441\u0443\u0436\u0430\u0435\u043c \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d.<\/p>\n<p>  <em><font color=\"blue\">\u041d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435 \u0444\u0438\u043b\u044c\u043c\u044b \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438<\/font><\/em><\/p>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0441\u043b\u043e\u0432\u0430\u043c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u0438\u043f\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u0430\u0437\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0447\u0442\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>  <code>Mongodb<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0412 Python \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c <code>re<\/code> \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.  <\/p>\n<pre><code class=\"python\">import re re_hacker = re.compile(r'.*hacker.*', re.IGNORECASE)  query = db.products.find({'type': 'Film', 'title': re_hacker}).sort([('details.issue_date', -1)]) <\/code><\/pre>\n<p>  Mongodb \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u043b\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u0435\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>re<\/code>. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443.<\/p>\n<pre><code class=\"python\">query = db.products.find({ 'type': 'Film', 'title': {'$regex': '.*hacker.*', '$options':'i'}}).sort([('details.issue_date', -1)]) <\/code><\/pre>\n<p>  <code>$options<\/code> \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441:<\/p>\n<pre><code class=\"python\">db.products.ensure_index([ ('type', 1), ('details.issue_date', -1), ('title', 1) ]) <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0446\u0435\u043b\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435 <code>title<\/code>.<\/p>\n<h4>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 ( Sharding ) <\/h4>\n<p>  \u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0448\u0430\u0440\u0434\u0438\u043d\u0433 \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u043e\u0433\u0434\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0435\u0437\u0430\u0442\u044c \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c.<br \/>  \u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0448\u0430\u0440\u0434\u043e\u0432 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c <code>shard key<\/code>, \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 <code>mongos<\/code> \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u0448\u0430\u0440\u0434\u0430 \u0438\u043b\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u0448\u0430\u0440\u0434\u043e\u0432.<\/p>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u0435 <code>type<\/code>, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 <code>shard key<\/code>. \u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 <code>shard key<\/code> \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c:  <\/p>\n<ul>\n<li><code>details.issue_date <\/code> \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 <code>shard key<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u043b\u0435 \u043d\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435.<\/li>\n<li>\u041d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0432 <code>detail<\/code> \u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u043c\u0438.<\/li>\n<\/ul>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0447\u0442\u043e \u043f\u043e\u043b\u0435 <code> details.genre <\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u043e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0435\u043c \u043f\u043e\u0441\u043b\u0435 <code>type<\/code>. \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code> Python\/PyMongo<\/code>  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; db.command('shardCollection', 'product', {  key : { 'type': 1, 'details.genre' : 1, 'sku':1 } } ) { &quot;collectionsharded&quot; : &quot;details.genre&quot;, &quot;ok&quot; : 1 } <\/code><\/pre>\n<p>  \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0439 <code>shard key<\/code>, \u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043e\u0442 \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u0430:  <\/p>\n<ol>\n<li>\u0428\u0430\u0440\u0434\u0438\u043d\u0433 \u0434\u0430\u0441\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0431\u044a\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432.<\/li>\n<li><code>MongoDB<\/code> \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0448\u0430\u0440\u0434\u0430\u043c, \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044f \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443.<\/li>\n<\/ol>\n<h5>\u0427\u0442\u0435\u043d\u0438\u0435<\/h5>\n<p>  \u0425\u043e\u0442\u044f \u0448\u0430\u0440\u0434\u0438\u043d\u0433 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b <code>mongos<\/code> \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u043b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043d\u0443\u0436\u043d\u044b\u043c \u0448\u0430\u0440\u0434\u0430\u043c.<br \/>  \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <code>mongos<\/code> \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0440\u0430\u0437\u0443 \u043a\u043e \u0432\u0441\u0435\u043c \u0448\u0430\u0440\u0434\u0430\u043c, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0443\u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<br \/>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u0441\u0447\u0435\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0436\u0435\u043c \u0441 \u043a\u0430\u043a\u043e\u0433\u043e \u0448\u0430\u0440\u0434\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u0447\u0438\u0442\u0430\u0442\u044c.<\/p>\n<p>  \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>SECONDARY<\/code> \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430 (\u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e) \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.  <\/p>\n<pre><code class=\"python\">conn = pymongo.MongoClient(read_preference=pymongo.SECONDARY) <\/code><\/pre>\n<p>  <code>SECONDARY_ONLY<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430.  <\/p>\n<pre><code class=\"python\">conn = pymongo.MongoClient(read_preference=pymongo.SECONDARY_ONLY) <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c <code>read_preference<\/code> \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">results = db.product.find(..., read_preference=pymongo.SECONDARY) <\/code><\/pre>\n<p>  \u0438\u043b\u0438  <\/p>\n<pre><code class=\"python\">results = db.product.find(..., read_preference=pymongo.SECONDARY_ONLY) <\/code><\/pre>\n<h3><a name=\"3\"><\/a> <font color=\"green\"> \u041a\u043e\u0440\u0437\u0438\u043d\u0430 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c\u0438 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435<\/font><\/h3>\n<p>  \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u043c\u0430\u0433\u0430\u0437\u0438\u043d\u043e\u0432 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0441\u0432\u043e\u0435\u0439 \u00ab\u043a\u043e\u0440\u0437\u0438\u043d\u044b\u00bb, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u0430 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u043e\u043a\u0443\u043f\u043e\u043a \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0435\u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u0430\u043a\u0430\u0437.<\/p>\n<p>  \u0412\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u044f\u0442\u044c \u0443\u0447\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u00ab\u043a\u0443\u043f\u0438\u0442\u044c\u00bb \u0442\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/p>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0431\u0443\u0434\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u0430, \u0442\u043e \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u0441\u043d\u043e\u0432\u0430 \u0441\u0442\u0430\u043d\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432\u0441\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0438 \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0438\u0449\u0435\u043d\u0430. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/dc4\/4c7\/77a\/dc44c777a24dc25eb4dbff115df2e865.png\"\/><\/p>\n<p>  \u0412 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e <code>Inventory<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0430\u0441\u043e\u0432 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0441\u043a\u043b\u0430\u0434\u0441\u043a\u043e\u0433\u043e \u0443\u0447\u0435\u0442\u0430 ( <a href=\"https:\/\/ru.wikipedia.org\/wiki\/SKU\">SKU<\/a>; \u0438\u043b\u0438 item), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0440\u0437\u0438\u043d \u0441 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439. \u0422\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435, \u043d\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u043e\u0439 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>_id<\/code> \u043f\u043e\u043b\u0435 \u0445\u0440\u0430\u043d\u044f\u0449\u0435\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/SKU\">SKU<\/a><\/p>\n<pre><code class=\"python\"># \u0412 \u044d\u0442\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f _id:SKU,  \u0442\u0430\u043a\u0436\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 16 \u0448\u0442\u0443\u043a, 1 \u0448\u0442. \u0432            # \u043a\u043e\u0440\u0437\u0438\u043d\u0435 \u0441 id 42, \u0438 2 \u0448\u0442. \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435 c id 43. \u042d\u0442\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u043e\u0431\u0449\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 19 \u043d\u0435 \u043f\u0440\u043e\u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446 \u0442\u043e\u0432\u0430\u0440\u0430. {     _id: '00e8da9b',     qty: 16,     carted: [         { qty: 1, cart_id: 42, timestamp: ISODate(&quot;2012-03-09T20:55:36Z&quot;) },         { qty: 2, cart_id: 43, timestamp: ISODate(&quot;2012-03-09T21:55:36Z&quot;) },     ] } <\/code><\/pre>\n<p>  <i>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u0445\u0435\u043c\u0430, \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0445\u0435\u043c\u0443 \u0441 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u043c \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0433\u043b\u0430\u0432\u0435.<\/i><\/p>\n<p>  \u0414\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043c\u044b \u043d\u0443\u0436\u0434\u0430\u0435\u043c\u0441\u044f \u0432 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/SKU\">SKU<\/a>, <code>quantity<\/code> \u043f\u043e\u043b\u044f\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432 \u043a\u0430\u043a\u0438\u0445 \u0442\u043e \u0443\u0442\u043e\u0447\u043d\u044f\u044e\u0449\u0438\u0445 \u043f\u043e\u043b\u044f\u0445, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u0432 <code>item_details<\/code>  <\/p>\n<pre><code class=\"python\"># \u041f\u043e\u043b\u0435 item_details \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u043a\u043e\u0440\u0437\u0438\u043d\u044b  # \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u0435 \u0434\u0435\u043b\u0430\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u044d\u0442\u0438\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0442\u043e\u0432\u0430\u0440\u043e\u0432. {     _id: 42,     last_modified: ISODate(&quot;2012-03-09T20:55:36Z&quot;),     status: 'active',     items: [         { sku: '00e8da9b', qty: 1, item_details: {...} },         { sku: '0ab42f88', qty: 4, item_details: {...} }     ] } <\/code><\/pre>\n<h4>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438<\/p>\n<h4><em><font color=\"blue\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0443<\/font><\/em><\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u0440\u0437\u0438\u043d\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u0432\u0430\u0440\u0430 \u0438\u0437 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u0430\u043f\u0430\u0441\u043e\u0432 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435 \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0443.<br \/>  \u0412\u0430\u0436\u043d\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0443 \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u0432\u0430\u0440. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>add_item_to_cart<\/code>.<\/p>\n<pre><code class=\"python\">def add_item_to_cart(cart_id, sku, qty, details):     now = datetime.utcnow()      # \u0423\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u043f\u043e \u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0430\u043a\u0442\u0438\u0432\u043d\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u043e\u0432\u0430\u0440     result = db.cart.update(         {'_id': cart_id, 'status': 'active' },         {'$set': {'last_modified':now}, '$push': {'items': {'sku':sku, 'qty':qty, 'details':details}}},         w=1      )     if not result['updatedExisting']:         raise CartInactive()      # \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043e\u0441\u0442\u0430\u0442\u043a\u0438     result = db.inventory.update(         {'_id':sku, 'qty': {'$gte': qty}},         {'$inc': {'qty':-qty}, '$push': {'carted': {'qty':qty, 'cart_id':cart_id, 'timestamp':now}}},          w=1     )     if not result['updatedExisting']:         # \u0415\u0441\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0442\u043e \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u043d\u0435\u0435 \u0442\u043e\u0432\u0430\u0440.         db.cart.update( {'_id': cart_id }, { '$pull': { 'items': {'sku': sku } } })         raise InadequateInventory() <\/code><\/pre>\n<p>  <i>\u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u0435 <code>_id<\/code> \u0438\u043d\u0434\u0435\u043a\u0441 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/i><br \/>  \u041f\u0435\u0440\u0432\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0447\u0442\u043e \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0442\u0443\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0432\u0430\u0440. \u0422\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435 \u0438 \u0435\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0438\u0445.<br \/>  \u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435 \u043d\u0435\u0442 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0440\u0437\u0438\u043d\u0443, \u0443\u0434\u0430\u043b\u044f\u044f \u0438\u0437 \u043d\u0435\u0451 \u0442\u043e\u0432\u0430\u0440.<\/p>\n<p>  <em><font color=\"blue\">\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435<\/font><\/em><\/p>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435, \u043e\u043d\u0438 \u0435\u0441\u0442\u044c \u0432 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435.  <\/p>\n<pre><code class=\"python\"> def update_quantity(cart_id, sku, old_qty, new_qty):     # \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u043b\u044f \u043f\u043e\u043b\u044f _id \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.     now = datetime.utcnow()     delta_qty = new_qty - old_qty      # \u0423\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u043f\u043e \u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0430\u043a\u0442\u0438\u0432\u043d\u0430 \u0438 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u0432\u0430\u0440\u043d\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e.     result = db.cart.update(          {'_id': cart_id, 'status': 'active', 'items.sku': sku },          {'$set': { 'last_modified': now, 'items.$.qty': new_qty } },           w=1     )     if not result['updatedExisting']:         raise CartInactive()      # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432     result = db.inventory.update(         {'_id':sku, 'carted.cart_id': cart_id, 'qty': {'$gte': delta_qty} },          {'$inc': {'qty': -delta_qty },'$set': { 'carted.$.qty': new_qty, 'timestamp': now } },          w=1     )     if not result['updatedExisting']:         # \u0415\u0441\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0442\u0430\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432         db.cart.update( {'_id': cart_id, 'items.sku': sku }, {'$set': { 'items.$.qty': old_qty } } )         raise InadequateInventory() <\/code><\/pre>\n<p>  <em><font color=\"blue\">\u041e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0441\u0434\u0435\u043b\u043a\u0438<\/font><\/em><\/p>\n<p>  \u0412 \u043a\u043e\u043d\u0446\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u043b\u0430\u0442\u044b \u0438, \u0435\u0441\u043b\u0438 \u043e\u043f\u043b\u0430\u0442\u0430 \u043f\u0440\u043e\u0448\u043b\u0430, \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0440\u0437\u0438\u043d\u0443.  <\/p>\n<pre><code class=\"python\">def checkout(cart_id):     now = datetime.utcnow()      # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0447\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b &lt;code&gt;active&lt;\/code&gt; \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 &lt;code&gt;pending&lt;\/code&gt;.      # \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0435\u0442\u0430\u043b\u0438 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0435\u043a     cart = db.cart.find_and_modify(          {'_id': cart_id, 'status': 'active' },           update={'$set': { 'status': 'pending','last_modified': now } }      )     if cart is None:         raise CartInactive()      # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u0435\u0442\u0430\u043b\u0438 \u043e\u043f\u043b\u0430\u0442\u044b; \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f payment     try:         collect_payment(cart)         db.cart.update( {'_id': cart_id }, {'$set': { 'status': 'complete' } } )         db.inventory.update( {'carted.cart_id': cart_id}, {'$pull': {'cart_id': cart_id} }, multi=True)     except:         db.cart.update( {'_id': cart_id }, {'$set': { 'status': 'active' } } )         raise  <\/code><\/pre>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <code>pending<\/code>. \u0422\u043e\u0433\u0434\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0431\u043d\u043e\u0432\u0438\u0442 \u043a\u043e\u0440\u0437\u0438\u043d\u0443 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0434\u0435\u0442\u0430\u043b\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043f\u043b\u0430\u0442\u0435\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.  <\/p>\n<ul>\n<li>\u0415\u0441\u043b\u0438 \u043e\u043f\u043b\u0430\u0442\u0430 \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0443\u0434\u0430\u043b\u0438\u0442 <code>cart_id<\/code> \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <code>inventory<\/code>. \u0418 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b <code>complete<\/code>.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043f\u043b\u0430\u0442\u0435\u0436 \u0431\u044b\u043b \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0440\u0437\u0438\u043d\u0443, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0438 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u043e\u043f\u043b\u0430\u0442\u044b.<\/li>\n<\/ul>\n<p>  <em><font color=\"blue\">\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434.<\/font><\/em><br \/>  \u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043e\u0431\u043d\u0443\u043b\u044f\u0442\u044c \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0442\u043e\u0432\u0430\u0440\u044b \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0441\u043a\u043b\u0430\u0434.<br \/>  \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>timeout<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0440\u0437\u0438\u043d\u044b.  <\/p>\n<pre><code class=\"python\">def expire_carts(timeout):     now = datetime.utcnow()     threshold = now - timedelta(seconds=timeout)     # \u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0431\u0435\u0437\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u0440\u0437\u0438\u043d     db.cart.update(          {'status': 'active', 'last_modified': { '$lt': threshold } },           {'$set': { 'status': 'expiring' } },           multi=True      )     # \u0418\u0434\u0435\u043c \u043f\u043e \u0431\u0435\u0437\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0440\u0437\u0438\u043d\u0430\u043c     for cart in db.cart.find({'status': 'expiring'}):         # \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0432\u0441\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u043d\u0430 \u0441\u043a\u043b\u0430\u0434         for item in cart['items']:             db.inventory.update(                 { '_id': item['sku'],  'carted.cart_id': cart['id'], 'carted.qty': item['qty'] },                 {'$inc': { 'qty': item['qty'] }, '$pull': { 'carted': { 'cart_id': cart['id'] } } }              )         db.cart.update( {'_id': cart['id'] }, {'$set': { 'status': 'expired' }) <\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f:  <\/p>\n<ul>\n<li>\u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0430\u0440\u0448\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/li>\n<li>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u0432\u0441\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435.<\/li>\n<li>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u044b \u043d\u0430 \u0441\u043a\u043b\u0430\u0434, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b <code>expired<\/code>.<\/li>\n<\/ul>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043f\u043e\u043b\u044f <code>status<\/code> \u0438 <code>last_modified<\/code>.  <\/p>\n<pre><code class=\"python\">db.cart.ensure_index([('status', 1), ('last_modified', 1)]) <\/code><\/pre>\n<p>  <em><font color=\"blue\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a.<\/font><\/em><br \/>  \u0412\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442 \u043e\u0434\u043d\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443: \u0435\u0441\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <code>inventory<\/code>, \u0442\u043e \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0443\u0436\u0435 \u0438\u0441\u0442\u0435\u043a\u043b\u043e, \u0430 \u0442\u043e\u0432\u0430\u0440\u044b \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u043b\u0438\u0441\u044c \u043d\u0430 \u0441\u043a\u043b\u0430\u0434.<\/p>\n<p>  \u0427\u0442\u043e\u0431 \u0443\u0447\u0435\u0441\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0447\u0438\u0441\u0442\u043a\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0432 <code>inventory<\/code> \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 <code>carted<\/code> \u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0442\u043e \u043e\u043d\u0438 \u0442\u043e\u0447\u043d\u043e \u0435\u0441\u0442\u044c \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435.<\/p>\n<pre><code class=\"python\">def cleanup_inventory(timeout):     now = datetime.utcnow()     threshold = now - timedelta(seconds=timeout)      # \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441 \u0438\u0441\u0442\u0435\u043a\u0448\u0438\u043c \u0441\u0440\u043e\u043a\u043e\u043c     for item in db.inventory.find( {'carted.timestamp': {'$lt': threshold }}):         carted = dict(             (carted_item['cart_id'], carted_item) for carted_item in item['carted'] if carted_item['timestamp'] &lt; threshold          )         # \u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434: \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043b\u044e\u0431\u044b\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u043c carted, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 inventory             for cart in db.cart.find( { '_id': {'$in': carted.keys() }, 'status':'active'}):             cart = carted[cart['_id']]             db.inventory.update(                 {'_id': item['_id'], 'carted.cart_id':cart['_id'] },                  { '$set': {'carted.$.timestamp':now }}             )             del carted[cart['_id']]          # \u0412\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0445\u043e\u0434: \u0412\u0441\u0435 carted \u043f\u0440\u0438\u0441\u0443\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u044b \u043d\u0430 \u0441\u043a\u043b\u0430\u0434.         for cart_id, carted_item in carted.items():             db.inventory.update(                 { '_id': item['_id'], 'carted.cart_id': cart_id,  'carted.qty': carted_item['qty'] },                 { '$inc': { 'qty': carted_item['qty'] }, '$pull': { 'carted': { 'cart_id': cart_id } } }             ) <\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u00abcarted\u00bb \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u0441\u0442\u0430\u0440\u0448\u0435, \u0447\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 <code>timeout<\/code>. \u0418 \u0437\u0430\u0442\u0435\u043c \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u044d\u0442\u0438\u043c \u043f\u0443\u043d\u043a\u0442\u0430\u043c:  <\/p>\n<ul>\n<li>\u0418\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043c\u0435\u0442\u043a\u0430\u043c\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0442\u0430\u0440\u0448\u0435 <code>timeout<\/code>, \u0435\u0441\u043b\u0438 \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0430\u043a\u0442\u0438\u0432\u043d\u0430, \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u044f.<\/li>\n<li>\u0418 \u0442\u043e\u0432\u0430\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434.<\/li>\n<\/ul>\n<p>  <em><font color=\"blue\">\u0428\u0430\u0440\u0434\u0438\u043d\u0433<\/font><\/em><br \/>  \u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0438\u043c \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0434\u043b\u044f <code>shard key<\/code> \u0431\u0443\u0434\u0435\u0442 <code>_id<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u043e\u043b\u0435 <code>_id<\/code>.<br \/>  \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 <code> mongos<\/code> \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u043f\u043e <code> _id<\/code> \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 <code>mongod<\/code>.<\/p>\n<p>  \u041d\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code> _id<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <code>shard key<\/code>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 <code>_id<\/code> \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <code>cart<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043e\u043c, \u0442\u043e \u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0448\u0430\u0440\u0434\u0435.<\/p>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u044d\u0444\u0444\u0435\u043a\u0442, \u0432\u044b\u0431\u0438\u0440\u0430\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0445\u044d\u0448 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 MD5 \u0438\u043b\u0438 SHA-1) \u0438\u0437 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 ObjectID, \u043a\u0430\u043a _id.<br \/>  \u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"python\">import hashlib import bson  cart_id = bson.ObjectId() cart_id_hash = hashlib.md5(str(cart_id)).hexdigest()  cart = { &quot;_id&quot;: cart_id, &quot;cart_hash&quot;: cart_id_hash } db.cart.insert(cart) <\/code><\/pre>\n<p>  \u0412\u0440\u0435\u043c\u044f \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0438 \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0448\u0438\u0440\u043e\u043a\u043e\u0432\u0435\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a\u043e \u0432\u0441\u0435\u043c \u0448\u0430\u0440\u0434\u0430\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <code> _id<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <code>shard key<\/code>.<\/p>\n<p>  \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c, \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0447\u0430\u0441\u0442\u043e, \u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u043c\u0435\u0434\u043b\u0438\u0442\u044c (\u0443\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Sleep ()<\/code>), \u0447\u0442\u043e\u0431\u044b \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440. <\/p>\n<p>  \u0414\u043b\u044f \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python\/PyMongo \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; db.command('shardCollection', 'inventory',  'key': { '_id': 1 } ) { &quot;collectionsharded&quot; : &quot;inventory&quot;, &quot;ok&quot; : 1 } &gt;&gt;&gt; db.command('shardCollection', 'cart',   'key': { '_id': 1 } ) { &quot;collectionsharded&quot; : &quot;cart&quot;, &quot;ok&quot; : 1 } <\/code><\/pre>\n<h3><a name=\"4\"><\/a> <font color=\"green\"> \u0418\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439<\/font><\/h3>\n<p>  \u0411\u0443\u0434\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u0440\u0435\u0432\u043e \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u0441 \u0442\u043e\u0432\u0430\u0440\u0430\u043c\u0438. \u041a\u0430\u0436\u0434\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u0441\u0432\u043e\u0451\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0435\u0434\u043a\u043e\u0432 \u0438\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439.<br \/>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0436\u0430\u043d\u0440\u043e\u0432:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/docs.mongodb.org\/ecosystem\/_images\/use-cases-category1.png\"\/><br \/>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u0438 \u0432\u0438\u0434\u044b \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0447\u0430\u0441\u0442\u043e, \u043d\u0430\u0448\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u042d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430:  <\/p>\n<ul>\n<li>\u041a\u0430\u0436\u0434\u0443\u044e \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e \u0432 \u0434\u0435\u0440\u0435\u0432\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u0438\u043d \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442<\/li>\n<li><code>Objectid<\/code> \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a.<\/li>\n<li>\u041a\u0430\u0436\u0434\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0435\u0439 \u0438\u043c\u0435\u0435\u0442 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0435 \u0438\u043c\u044f \u0438 \u043f\u043e\u043b\u0435 \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c URL-\u0430\u0434\u0440\u0435\u0441\u043e\u043c.<\/li>\n<li>\u0421\u0445\u0435\u043c\u0430 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0435\u0434\u043a\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441.<\/li>\n<\/ul>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f:  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : ObjectId(&quot;4f5ec858eb03303a11000002&quot;),   &quot;name&quot; : &quot;Modal Jazz&quot;,   &quot;parent&quot; : ObjectId(&quot;4f5ec858eb03303a11000001&quot;),   &quot;slug&quot; : &quot;modal-jazz&quot;,   &quot;ancestors&quot; : [          { &quot;_id&quot; : ObjectId(&quot;4f5ec858eb03303a11000001&quot;), &quot;slug&quot; : &quot;bop&quot;,  &quot;name&quot; : &quot;Bop&quot; },          { &quot;_id&quot; : ObjectId(&quot;4f5ec858eb03303a11000000&quot;), &quot;slug&quot; : &quot;ragtime&quot;, &quot;name&quot; : &quot;Ragtime&quot; }       ] } <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0434\u0435\u0440\u0435\u0432\u043e\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0432 E-Commerce \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445. \u0412\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Python\/PyMongo<\/code><\/p>\n<p>  <em><font color=\"blue\">\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043a\u0430\u0437 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439<\/font><\/em><br \/>  \u0417\u0430\u043f\u0440\u043e\u0441.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0446\u0438\u0438 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043a\u0430\u0437\u0430 \u0434\u0435\u0440\u0435\u0432\u0430 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439. \u0412 \u044d\u0442\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435 <code>slug<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 <code>\u201cbread crumb\u201d<\/code><\/p>\n<pre><code class=\"python\">category = db.categories.find({'slug':slug}, {'_id':0, 'name':1, 'ancestors.slug':1, 'ancestors.name':1 }) <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u043f\u043e\u043b\u044e <code>slug<\/code>.<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; db.categories.ensure_index('slug', unique=True) <\/code><\/pre>\n<p>  <em><font color=\"blue\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438<\/font><\/em><br \/>  \u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0451 \u043f\u0440\u0435\u0434\u043a\u043e\u0432. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e &#8212;<code>Swing<\/code> \u0432 \u0432\u0438\u0434\u0435 \u043f\u043e\u0442\u043e\u043c\u043a\u0430 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 <code>Ragtime<\/code>, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0441\u0445\u0435\u043c\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/docs.mongodb.org\/ecosystem\/_images\/use-cases-category2.png\"\/><\/p>\n<p>  \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u0434\u043a\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043a\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def build_ancestors(_id, parent_id):     parent = db.categories.find_one({'_id': parent_id}, {'name': 1, 'slug': 1, 'ancestors':1})     parent_ancestors = parent.pop('ancestors')     ancestors = [ parent ] + parent_ancestors     db.categories.update({'_id': _id}, {'$set': { 'ancestors': ancestors } }) <\/code><\/pre>\n<p>  \u041d\u0443\u0436\u043d\u043e \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u043d\u0430 \u043e\u0434\u0438\u043d \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u0432\u0435\u0440\u0445 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0435\u0434\u043a\u043e\u0432 \u0434\u043b\u044f <code>Ragtime<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u0440\u0435\u0434\u043a\u043e\u0432 <code>Swing<\/code>.<br \/>  \u0422\u043e\u0433\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">doc = dict(name='Swing', slug='swing', parent=ragtime_id) swing_id = db.categories.insert(doc) build_ancestors(swing_id, ragtime_id) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043d\u0430\u043c \u0445\u0432\u0430\u0442\u0438\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0430 <code>_id<\/code><\/p>\n<p>  <em><font color=\"blue\">\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u043a\u043e\u0432 \u0443 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438<\/font><\/em><br \/>  \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430, \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e <code>bop<\/code> \u043d\u0430\u0434 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0435\u0439 <code>swing<\/code>. <br \/>  <img decoding=\"async\" src=\"http:\/\/docs.mongodb.org\/ecosystem\/_images\/use-cases-category3.png\"\/><\/p>\n<p>  \u041e\u0431\u043d\u043e\u0432\u0438\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 <code>bop<\/code> \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f:  <\/p>\n<pre><code class=\"python\">db.categories.update({'_id':bop_id}, {'$set': { 'parent': swing_id } } ) <\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u043e\u0438\u0442 \u043f\u043e\u043b\u0435 \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043a\u0438.<\/p>\n<pre><code class=\"python\">def build_ancestors_full(_id, parent_id):     ancestors = []     while parent_id is not None:         parent = db.categories.find_one({'_id': parent_id}, {'parent': 1, 'name': 1, 'slug': 1, 'ancestors':1})         parent_id = parent.pop('parent')         ancestors.append(parent)     db.categories.update({'_id': _id}, {'$set': { 'ancestors': ancestors } })  <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0446\u0438\u043a\u043b \u0434\u043b\u044f \u0440\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 <code>bop<\/code><\/p>\n<pre><code class=\"python\">for cat in db.categories.find({'ancestors._id': bop_id}, {'parent': 1}):     build_ancestors_full(cat['_id'], cat['parent']) <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u043f\u043e\u043b\u044f <code>ancestors._id<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">db.categories.ensure_index('ancestors._id') <\/code><\/pre>\n<p>  <em><font color=\"blue\">\u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438<\/font><\/em><br \/>  \u0414\u043b\u044f \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u0441\u0430\u043c\u0443 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e \u0442\u0430\u043a \u0438 \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432.<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u201cBop\u201d \u0432 \u201cBeBop\u201d \u044d\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u043e \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/docs.mongodb.org\/ecosystem\/_images\/use-cases-category4.png\"\/><br \/>  \u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u2014 \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u043c\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438:<\/p>\n<pre><code class=\"python\">db.categories.update({'_id':bop_id}, {'$set': { 'name': 'BeBop' } }) <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0435\u0434\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\">db.categories.update({'ancestors._id': bop_id}, {'$set': { 'ancestors.$.name': 'BeBop' } }, multi=True) <\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442:  <\/p>\n<ul>\n<li>\u041f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 $ \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043a\u0430 \u043d\u0435 \u0437\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e \u0435\u0433\u043e <code>_id<\/code>.<\/li>\n<li>\u041e\u043f\u0446\u0438\u044e <code>multi<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u0434\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0434 \u0443\u0441\u043b\u043e\u0432\u0438\u0435.<\/li>\n<\/ul>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 <code>ancestors._id<\/code>.<\/p>\n<p>  <em><font color=\"blue\">\u0428\u0430\u0440\u0434\u0438\u043d\u0433<\/font><\/em><\/p>\n<p>  \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0448\u0430\u0440\u0434\u0438\u043d\u0433 \u044d\u0442\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u0443\u044e \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u0435\u043d \u0448\u0430\u0440\u0434 \u0442\u043e \u0434\u043b\u044f <code>shard key<\/code> \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u043f\u043e\u043b\u0435 <code>_id<\/code>.<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; db.command('shardCollection', 'categories', {  'key': {'_id': 1} }) { &quot;collectionsharded&quot; : &quot;categories&quot;, &quot;ok&quot; : 1 } <\/code><\/pre>\n<p>  P.S. \u041f\u0440\u043e\u0441\u044c\u0431\u0430 \u043e \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043b\u0438\u0447\u043a\u0443.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b:<\/p>\n<p>  <a href=\"http:\/\/docs.mongodb.org\/ecosystem\/#use-cases\"> \u042d\u043a\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0430 MongoDB <\/a><br \/>  <a href=\"http:\/\/docs.mongodb.org\/manual\/reference\/operator\/aggregation\/\">\u0421\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c \u0432 aggregation framework<\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/217393\/\">\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u043e \u0448\u0430\u0440\u0434\u0438\u043d\u0433 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435<\/a><br \/>  <a href=\"http:\/\/design-pattern.ru\/\">\u0421\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u00ab\u041f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u00bb (ru)<\/a><\/h4>\n<\/h4>\n<p><\/em><\/em><\/em><\/em><\/em><\/em><\/em>     \t<\/p>\n<div class=\"clear\"><\/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\/260291\/\"> http:\/\/habrahabr.ru\/post\/260291\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/e36\/58a\/ca6\/e3658aca69ab496895f5bc53c7357632.jpeg\"\/><\/p>\n<p>  <a href=\"http:\/\/habrahabr.ru\/post\/259219\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a> <br \/>  \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u043e\u0441\u044c \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c. \u042d\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 <code>aggregation framework<\/code> \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0442\u0440\u0435\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 <a href=\"http:\/\/docs.mongodb.org\/ecosystem\/#use-cases\">\u044d\u043a\u043e\u0441\u0438\u0442\u0435\u043c\u0430<\/a> \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0441\u043e \u0441\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043a <code>MongoDB<\/code>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u043a\u043e\u043c\u043c\u0435\u0440\u0446\u0438\u0438.<\/p>\n<p>  \u0421\u043b\u0443\u0447\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0442\u0430\u043c \u043d\u0430 \u0432\u043e\u0441\u0435\u043c\u044c \u0441\u0442\u0430\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0442\u0440\u0438 \u0433\u0440\u0443\u043f\u043f\u044b. \u041c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u0441\u0430\u043c\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0442\u0440\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 <code>e-commerce<\/code>.<\/p>\n<ol>\n<li><a href=\"#1\">\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 aggregation framework<\/a><\/li>\n<li><a href=\"#2\"> \u041a\u0430\u0442\u0430\u043b\u043e\u0433 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432<\/a><\/li>\n<li><a href=\"#3\"> \u041a\u043e\u0440\u0437\u0438\u043d\u0430 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c\u0438 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435 <\/a><\/li>\n<li><a href=\"#4\"> \u0418\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439<\/a><\/li>\n<\/ol>\n<p>  <\/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-259318","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/259318","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=259318"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/259318\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=259318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=259318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=259318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}