{"id":258435,"date":"2015-06-01T20:51:02","date_gmt":"2015-06-01T16:51:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=258435"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=258435","title":{"rendered":"\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e mongodb: e-commerce, \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f, \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0438\u043d\u0438\u043c\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445"},"content":{"rendered":"<p>     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/e36\/58a\/ca6\/e3658aca69ab496895f5bc53c7357632.jpeg\"\/><\/p>\n<p>  \u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u2014 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e <code>mongodb<\/code> \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043f\u0430\u0440\u043e\u0439 \u0440\u0435\u0446\u0435\u043f\u0442\u043e\u0432. \u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043c\u0435\u043b\u043e\u0447\u0438 \u0441\u043e\u0431\u0440\u0430\u043d\u044b \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f <code>mongodb<\/code> \u043d\u0430\u0439\u0434\u0435\u0442 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435.<\/p>\n<p>  \u041d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0442 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u0441\u044f \u0432 \u043a\u043b\u044e\u0447\u0435 \u0445\u043e\u043b\u0438\u0432\u0430\u0440\u043e\u0432 \u043d\u0430 \u0442\u0435\u043c\u0443 <code>SQL vs. NOSQL<\/code> \u0418 \u0442\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0447\u0442\u043e \u0432\u0435\u0437\u0434\u0435 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043f\u0440\u0430\u0432\u043a\u0438, \u0433\u0434\u0435-\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0437 \u0442\u043e\u0433\u043e, \u0441 \u0447\u0435\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0430 <code>mongo shell<\/code> \u0438\u043b\u0438 \u043d\u0430 <code>python<\/code>.<\/p>\n<ol>\n<li><a href=\"#1\">\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0432 \u043d\u0430 \u043d\u043e\u0432\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0432 mongodb<\/a><br \/> \n<ul>\n<li><a href=\"#11\"> \u0414\u043e \u0432\u0435\u0440\u0441\u0438\u0438 2.6 <\/a><\/li>\n<li><a href=\"#12\"> \u0421 2.6 \u0434\u043e 3.0 \u0432\u0435\u0440\u0441\u0438\u0438 <\/a><\/li>\n<li><a href=\"#13\"> \u041d\u043e\u0432\u043e\u0435 \u0432 PyMongo <\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#2\"> \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435<\/a><\/li>\n<li><a href=\"#3\"> \u041f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a, regexp, \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0438 \u043f\u0440.<\/a><\/li>\n<li><a href=\"#4\"> \u0410\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b (\u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 )<\/a><\/li>\n<li><a href=\"#5\"> \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445 \u0432 Mongodb<\/a><br \/> \n<ul>\n<li><a href=\"#51\"> \u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 <\/a><\/li>\n<li><a href=\"#52\"> \u0414\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u043c\u043c\u0438\u0442 <\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#6\"> \u0410\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438 JOIN-\u044b<\/a><\/li>\n<li><a href=\"#7\"> \u041f\u0440\u0438\u043c\u0435\u0440\u044b <\/a><br \/> \n<ul>\n<li><a href=\"#71\"> \u0414\u0435\u0440\u0435\u0432\u044c\u044f, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438<\/a><\/li>\n<li><a href=\"#72\"> \u0422\u0435\u0433\u0438, \u0431\u043b\u043e\u0433\u0438 <\/a><\/li>\n<li><a href=\"#73\"> \u0415-commerce, \u0444\u0438\u043b\u044c\u0442\u0440\u044b <\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#8\"> \u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430 \u043d\u0430 Python<\/a><\/li>\n<\/ol>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h3><a name=\"1\"><\/a> <font color=\"green\">\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0432 mongodb<\/font><\/h3>\n<p>  <\/p>\n<h3><a name=\"11\"><\/a> <font color=\"blue\">\u0414\u043e \u0432\u0435\u0440\u0441\u0438\u0438 2.6<\/font><\/h3>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.6<\/code> \u0432 <code>mongodb<\/code> \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0431\u0430\u0437\u044b, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u0418, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c.<\/p>\n<p>  1) \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.4<\/code> \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044e <code>2.6<\/code>. \u0421 <code>2.2<\/code> \u043d\u0430 <code>2.6<\/code> \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u044d\u0442\u0430\u043f\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c.<\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0430\u043c\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"bash\">apt-get update apt-get install mongodb-org <\/code><\/pre>\n<p>  2) \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0438\u0441\u044c \u0434\u043e <code>2.6<\/code> \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u0432 \u0431\u0430\u0437\u0443 <code>admin<\/code> \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432.  <\/p>\n<pre><code class=\"bash\">use admin db.upgradeCheckAllDBs() <\/code><\/pre>\n<p>  3) \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 c \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.6<\/code> \u0432 <code>mongodb<\/code>, \u043a\u0430\u043a \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0440\u043e\u043b\u044f\u043c \u0438 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435, \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0442.\u0434., \u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430\u0434\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u044d\u0442\u0438 \u0440\u043e\u043b\u0438, \u0438\u043d\u0430\u0447\u0435 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>auth<\/code>.   <\/p>\n<pre><code class=\"bash\">db.auth('admin','password') <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u00ab\u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u00bb \u0432 \u0431\u0430\u0437\u0435 <code>admin<\/code>  <\/p>\n<pre><code class=\"bash\">db.createUser({user:&quot;admin&quot;, pwd:&quot;passwd&quot;, roles:[{role:&quot;userAdminAnyDatabase&quot;, db:&quot;admin&quot;}]}) <\/code><\/pre>\n<p>  4) \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0439\u0442\u0438 \u0432 \u0441\u0432\u043e\u044e \u043d\u0443\u0436\u043d\u0443\u044e \u0431\u0430\u0437\u0443, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f, \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.  <\/p>\n<pre><code class=\"bash\">use newdb db.createUser({user:&quot;admin&quot;, pwd:&quot;passwd&quot;, roles:[{role:&quot;dbAdmin&quot;, db:&quot;newdb&quot;}]}) <\/code><\/pre>\n<p>  \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0432 \u0431\u0430\u0437\u0435 <code>admin<\/code> \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <code>system.users<\/code><br \/>  \u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0431\u0430\u0437\u044b \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:  <\/p>\n<pre><code class=\"bash\">db.runCommand( { usersInfo: [ { user: &quot;admin&quot;, db: &quot;newdb&quot; } ], showPrivileges: true } ) <\/code><\/pre>\n<p>  \u041d\u0443 \u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e.  <\/p>\n<pre><code class=\"bash\">service mongod restart <\/code><\/pre>\n<p>  \u0412 <code>ubuntu<\/code> c \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 <code>mongodb<\/code> \u0430 <code>mongod<\/code> \u0430 \u043a\u043e\u043d\u0444\u0438\u0433 \u0432 <code>\/etc<\/code> \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>mongod.conf<\/code> \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0443\u0442\u0430\u0442\u044c.<\/p>\n<h3><a name=\"12\"><\/a> <font color=\"blue\">\u0421 2.6 \u0434\u043e 3.0 \u0432\u0435\u0440\u0441\u0438\u0438<\/font><\/h3>\n<p>  \u041e \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 <code>3.0<\/code> \u0438 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432 \u0434\u0432\u0438\u0436\u043a\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0431\u044b\u043b\u043e \u0443\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043c\u043d\u043e\u0433\u043e, \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f. <\/p>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u043e <code>3.0<\/code> \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.6<\/code> \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u043a\u0430\u043a\u0438\u0432\u0430\u044f. \u0422\u043e \u0435\u0441\u0442\u044c <code>2.2-&gt;2.4-&gt;2.6<\/code>.<br \/>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043d\u0435 \u043d\u0438\u0436\u0435 <code>2.6.5<\/code>.<br \/>  \u0421\u0430\u043c\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0434\u043b\u044f <code>ubuntu<\/code> \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430<br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 3-\u0439 \u0432\u0435\u0440\u0441\u0438\u0438:  <\/p>\n<pre><code class=\"bash\">sudo apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv 7F0CEB10  echo &quot;deb http:\/\/repo.mongodb.org\/apt\/ubuntu &quot;$(lsb_release -sc)&quot;\/mongodb-org\/3.0 multiverse&quot; | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-3.0.list <\/code><\/pre>\n<p>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c:  <\/p>\n<pre><code class=\"bash\">apt-get update apt-get install -y mongodb-org <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044e \u043f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435.  <\/p>\n<pre><code class=\"bash\">apt-get install -y mongodb-org=3.0.2 mongodb-org-server=3.0.2 mongodb-org-shell=3.0.2 mongodb-org-mongos=3.0.2 mongodb-org-tools=3.0.2 <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e:   <\/p>\n<pre><code class=\"bash\">service mongod stop service mongod start <\/code><\/pre>\n<p>  \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0435\u0440\u0441\u0438\u044e <code>mongodb<\/code>:  <\/p>\n<pre><code class=\"bash\">root@user-pc:~# mongo MongoDB shell version: 3.0.2 connecting to: test &gt; db.version() 3.0.2 &gt;  <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0435\u0440\u0441\u0438\u044f <code>3<\/code> \u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u043e\u0448\u043b\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0442\u043e\u0438\u0442 <code>MMAPv1<\/code>.<\/p>\n<p>  \u0414\u043b\u044f \u0441\u043c\u0435\u043d\u044b \u0432 <code>\/etc\/mongo.conf<\/code> \u0441\u0442\u0430\u0432\u0438\u043c \u043e\u043f\u0446\u0438\u044e:  <\/p>\n<pre><code class=\"bash\">storageEngine = wiredTiger <\/code><\/pre>\n<p>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c <a href=\"http:\/\/docs.mongodb.org\/manual\/reference\/program\/mongod\/#cmdoption--storageEngine\">\u0442\u0443\u0442<\/a><br \/>  \u0418 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e\u0431 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f <code>\/var\/lib\/mongodb<\/code> \u0431\u044b\u043b\u0430 \u043f\u0443\u0441\u0442\u043e\u0439 \u0438\u043d\u0430\u0447\u0435 <code>mongodb<\/code> \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>mongodump<\/code>  <\/p>\n<pre><code class=\"bash\">service mongod restart <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044e \u0434\u0432\u0438\u0436\u043a\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430:  <\/p>\n<pre><code class=\"bash\">root@user-pc:\/etc# mongo MongoDB shell version: 3.0.2 connecting to: test &gt; db.serverStatus() <\/code><\/pre>\n<p>  \u0418\u0449\u0435\u043c <code>storageEngine<\/code> \u0435\u0441\u043b\u0438 <code>wiredTiger<\/code> \u0442\u043e \u0432\u0441\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e.  <\/p>\n<pre><code class=\"bash\">&quot;storageEngine&quot; : { \t&quot;name&quot; : &quot;wiredTiger&quot; } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u044b, \u0432\u043a\u043b\u044e\u0447\u0430\u044f <code>admin<\/code>  <\/p>\n<pre><code class=\"bash\">mongorestore --port 27017 -d admin  <\/code><\/pre>\n<p>  <\/p>\n<h3><a name=\"13\"><\/a> <font color=\"blue\">\u041d\u043e\u0432\u043e\u0435 \u0432 PyMongo<\/font><\/h3>\n<p>  \u0412\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0431\u0430\u0437\u044b, \u0432\u044b\u0448\u043b\u0430 \u043d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0434\u043b\u044f <code>Python<\/code> <code>PyMongo<\/code>, \u0432 \u043d\u0435\u0439 \u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043f\u043e\u0441\u043b\u0435:  <\/p>\n<pre><code class=\"bash\">pip install -U pymongo <\/code><\/pre>\n<p>  \u0414\u0430\u0436\u0435 \u0431\u0435\u0437 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0430\u043c\u043e\u0439 \u0431\u0430\u0437\u044b, \u043d\u0435 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u0435\u0436\u0434\u0435. \u0418\u0437 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043e:  <\/p>\n<ol>\n<li>\u0414\u043b\u044f \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0443\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b <code>update_one, insert_many, find_one_and_delete<\/code> \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439 \u0432 <a href=\"https:\/\/github.com\/mongodb\/specifications\/blob\/master\/source\/crud\/crud.rst\">\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/a><\/li>\n<li>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0443\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0431\u044b\u043b \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440 \u043a \u0431\u0430\u0437\u0435 <code>MongoClient<\/code> \u0438\u0437 \u043d\u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u044b \u0442\u0430\u043a\u0438\u0435 \u043e\u043f\u0446\u0438\u0438 \u043a\u0430\u043a <code>'slave_okay': True<\/code>. <code>ReplicaSetConnection<\/code> \u0438 <code>MasterSlaveConnection<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u044b. <code>MongoReplicaSetClient<\/code> \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u043a\u0430\u043a\u043e\u0435 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<br \/> \n<pre><code class=\"bash\">&gt;&gt;&gt; # Connect to one standalone, mongos, or replica set member. &gt;&gt;&gt; client = MongoClient('mongodb:\/\/server') &gt;&gt;&gt; &gt;&gt;&gt; # Connect to a replica set. &gt;&gt;&gt; client = MongoClient('mongodb:\/\/member1,member2\/?replicaSet=my_rs') &gt;&gt;&gt; &gt;&gt;&gt; # Load-balance among mongoses. &gt;&gt;&gt; client = MongoClient('mongodb:\/\/mongos1,mongos2') <\/code><\/pre>\n<p>  <\/li>\n<li>\u0423\u0434\u0430\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434 <code>copy_database<\/code><\/li>\n<li>\u0423\u0434\u0430\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434 <code>end_request()<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>close()<\/code><\/li>\n<li>\u0427\u0430\u0441\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 \u043e\u0436\u0438\u0434\u0430\u043b\u0430, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 <code>asyncio<\/code> \u0438\u0437 <code>python3<\/code>, \u043d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443\u0432\u044b. \u0414\u043b\u044f <code>tornado<\/code> \u0435\u0441\u0442\u044c \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 <a href=\"https:\/\/motor.readthedocs.org\/en\/stable\/\">motor<\/a> \u0410 \u0434\u043b\u044f <code>asyncio<\/code>, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 <a href=\"https:\/\/bitbucket.org\/mrdon\/asyncio-mongo\/src\">asyncio-mongo<\/a> \u0441\u043b\u0430\u0431\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0438 \u0441 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <code>GridFS<\/code><\/li>\n<li>\u0412 \u0430\u0433\u0440\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u0443\u0440\u0441\u043e\u0440, \u0430 \u043d\u0435 <code>result<\/code>.<\/li>\n<\/ol>\n<h3><a name=\"4\"><\/a><font color=\"green\">\u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435<\/font><\/h3>\n<p>  <em><font color=\"blue\"><code>$eq<\/code> \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<\/font><\/em><br \/>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>$eq<\/code> \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d <code>db.test.find({ field: &lt;value&gt; })<\/code>.  <\/p>\n<pre><code class=\"python\">{ _id: 1, item: { name: &quot;ab&quot;, code: &quot;123&quot; }, qty: 15, tags: [ &quot;A&quot;, &quot;B&quot;, &quot;C&quot; ] } { _id: 2, item: { name: &quot;cd&quot;, code: &quot;123&quot; }, qty: 20, tags: [ &quot;B&quot; ] }  db.test.find( { qty: { $eq: 20 } } ) #\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d db.test.find( { qty: 20 } )  db.test.find( { tags: { $eq: [ &quot;A&quot;, &quot;B&quot; ] } } ) #\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e: db.test.find( { tags: [ &quot;A&quot;, &quot;B&quot; ] } )  <\/code><\/pre>\n<p>  <em><font color=\"blue\">$gt \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c<\/font><\/em><br \/>  <code>$gt<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435 <code>(&gt;)<\/code> \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.  <\/p>\n<pre><code class=\"bash\">db.test.find( { qty: { $gt: 10 } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$gte \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e \u0447\u0435\u043c<\/font><\/em><br \/>  <code>$gte<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e <code>(&gt;=)<\/code> \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.  <\/p>\n<pre><code class=\"bash\">db.test.find( { qty: { $gte: 10 } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$lt \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0435\u043c<\/font><\/em><br \/>  <code>$lt<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043c\u0435\u043d\u044c\u0448\u0435 <code>(&lt;)<\/code> \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e   <\/p>\n<pre><code class=\"bash\">db.test.find( { qty: { $lt: 10 } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$lte \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e \u0447\u0435\u043c<\/font><\/em><br \/>  <code>$lte<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e <code>(&lt;=)<\/code> \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e   <\/p>\n<pre><code class=\"bash\">db.test.find( { qty: { $lte: 10 } } ) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u0431\u044b\u043b\u044c \u043f\u0440\u043e\u0434\u0430\u0432\u0446\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 <code>100<\/code>, \u0442\u043e \u043f\u0440\u0435\u043c\u0438\u044f \u0430\u043d\u043d\u0443\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f.  <\/p>\n<pre><code class=\"bash\">db.test.update({ &quot;vendor.profit&quot;: { $lte: 100 } }, { $set: { premium: 0 } }) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$ne \u043d\u0435 \u0440\u0430\u0432\u043d\u043e<\/font><\/em><br \/>  <code>$ne<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043d\u0435 \u0440\u0430\u0432\u043d\u043e <code>(! =)<\/code> \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.  <\/p>\n<pre><code class=\"bash\">db.test.find( { qty: { $ne: 10 } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$in \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435<\/font><\/em>  <\/p>\n<pre><code class=\"bash\">{ _id: 1, qty: 10, tags: [ &quot;name&quot;, &quot;lastname&quot; ], } db.test.find({ tags: { $in: [&quot;name&quot;, &quot;lastname&quot;] } }  ) <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c  <\/p>\n<pre><code class=\"bash\">db.test.find( { tags: { $in: [ \/^be\/, \/^st\/ ] } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$nin \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043d\u0435\u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435<\/font><\/em><br \/>  \u0422\u043e\u0436\u0435 \u0447\u0442\u043e \u0438 <code>$in<\/code> \u043d\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435.  <\/p>\n<pre><code class=\"python\">db.test.find( { qty: { $nin: [ 5, 15 ] } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$or \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u043b\u0438<\/font><\/em><br \/>  \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>\u0438\u043b\u0438<\/code>, \u0431\u0435\u0440\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0447\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445.  <\/p>\n<pre><code class=\"python\">db.test.find( { $or: [ { quantity: { $lt: 10 } }, { price: 10 } ] } ) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0432\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430:  <\/p>\n<pre><code class=\"python\">db.test.createIndex( { quantity: 1 } ) db.test.createIndex( { price: 1 } ) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 <code>$or<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>$text<\/code>, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  <em><font color=\"blue\">$and \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u00ab\u0438\u00bb<\/font><\/em><br \/>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>\u0438<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445.  <\/p>\n<pre><code class=\"python\">db.test.find( { $and: [ { price:10 }, { check: true } } ] <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>$or<\/code>:  <\/p>\n<pre><code class=\"python\">db.test.find( {     $and : [         { $or : [ { price : 50 }, { price : 80 } ] },         { $or : [ { sale : true }, { qty : { $lt : 20 } } ] }     ] } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$not \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u044f<\/font><\/em><br \/>  \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0447\u0442\u043e\u0431\u044b \u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044e.  <\/p>\n<pre><code class=\"python\">db.test.find( { price: { $not: { $gt: 10 } } } ) <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c:  <\/p>\n<pre><code class=\"python\">import re for no_docs in db.test.find( { &quot;item&quot;: { &quot;$not&quot;: re.compile(&quot;^p.*&quot;) } } ):     print no_docs <\/code><\/pre>\n<p>  <em><font color=\"blue\">$nor \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0435 \u0438\u043b\u0438<\/font><\/em>  <\/p>\n<pre><code class=\"javascript\">db.test.find( { $nor: [ { price: 10 }, { qty: { $lt: 20 } }, { sale: true } ] } ) <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 test \u043d\u0430\u0439\u0434\u0435\u0442 \u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445:  <\/p>\n<ul>\n<li>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>price<\/code> \u043d\u0435 \u0440\u0430\u0432\u043d\u043e 10<\/li>\n<li>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>qty<\/code> \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 20<\/li>\n<li>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>sale<\/code> \u043d\u0435 <code>true<\/code><\/li>\n<\/ul>\n<p>  <em><font color=\"blue\">$exists \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u043b\u044f \u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435<\/font><\/em><br \/>  <code>$exists<\/code> \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442.<br \/>  \u0415\u0441\u043b\u0438 \u0443\u043a\u0430\u0436\u0435\u043c \u0443 <code>$exists<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>false<\/code>, \u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0435\u0440\u043d\u0435\u0442 \u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043a\u043b\u044e\u0447 <code>qty<\/code>.  <\/p>\n<pre><code class=\"python\">db.test.find( { qty: { $exists: true } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$type \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <code>BSON<\/code> \u0442\u0438\u043f\u0430<\/font><\/em>  <\/p>\n<pre><code class=\"python\">db.test.find( { field: { $type: -1 } } ); <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0442\u0438\u043f\u044b:<\/b><\/p>\n<div class=\"spoiler_text\">\n<table border=\"1\">\n<tbody>\n<tr>\n<td><strong>\u0422\u0438\u043f<\/strong><\/td>\n<td><strong>\u041d\u043e\u043c\u0435\u0440<\/strong><\/td>\n<td><strong>\u0410\u043d\u043e\u0442\u0430\u0446\u0438\u0438<\/strong><\/td>\n<\/tr>\n<tr>\n<td>Double<\/td>\n<td>1<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>String<\/td>\n<td>2<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Object<\/td>\n<td>3<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Array<\/td>\n<td>4<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Binary data<\/td>\n<td>5<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Undefined<\/td>\n<td>6<\/td>\n<td>Deprecated.<\/td>\n<\/tr>\n<tr>\n<td>Object id<\/td>\n<td>7<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Boolean<\/td>\n<td>8<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Date<\/td>\n<td>9<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>10<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Regular Expression<\/td>\n<td>11<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>JavaScript<\/td>\n<td>13<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Symbol<\/td>\n<td>14<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>JavaScript (with scope)<\/td>\n<td>15<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>32-bit integer<\/td>\n<td>16<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Timestamp<\/td>\n<td>17<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>64-bit integer<\/td>\n<td>18<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Min key<\/td>\n<td>255<\/td>\n<td>Query with -1.<\/td>\n<\/tr>\n<tr>\n<td>Max key<\/td>\n<td>127<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>  <\/div>\n<\/div>\n<p>  <em><font color=\"blue\">$mod<\/font><\/em><br \/>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>$mod<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043f\u043e\u043b\u0435\u0439, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0438 \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u0442\u043e\u0440\u043e\u043c\u0443. <br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b:  <\/p>\n<pre><code class=\"bash\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;aa123&quot;, &quot;qty&quot; : 0 } { &quot;_id&quot; : 2, &quot;item&quot; : &quot;bb123&quot;, &quot;qty&quot; : 7 } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;cc123&quot;,  &quot;qty&quot; : 15 } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441:  <\/p>\n<pre><code class=\"python\">db.test.find( { qty: { $mod: [ 5, 0 ] } } ) <\/code><\/pre>\n<p>  \u0412\u0435\u0440\u043d\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b:  <\/p>\n<pre><code class=\"bash\">{ &quot;_id&quot; : 1, &quot;item&quot; : &quot;aa123&quot;, &quot;qty&quot; : 0 } { &quot;_id&quot; : 3, &quot;item&quot; : &quot;cc123&quot;, &quot;qty&quot; : 15 } <\/code><\/pre>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433 \u0438\u0437 <code>SQL<\/code>   <\/p>\n<pre><code class=\"bash\">select * from t where qty % 5 = 0; <\/code><\/pre>\n<p>  C <code>2.6<\/code> \u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0440\u0430\u0449\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430. \u0422\u0430\u043a\u0436\u0435, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0442\u0440\u0435\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u043e\u0436\u0435 \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043b\u0438\u0448\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c.<br \/>  <em><font color=\"blue\">$all \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432\u0441\u0435\u043c<\/font><\/em><br \/>  \u0414\u0435\u043b\u0430\u0435\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.  <\/p>\n<pre><code class=\"python\">db.test.find( { tags: { $all: [ &quot;python&quot;, &quot;mongodb&quot;, &quot;javascript&quot; ] } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$elemMatch<\/font><\/em><br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0434\u0432\u0430 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443.<br \/>  \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0435\u0441\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e\u0434\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u0434 \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f.   <\/p>\n<pre><code class=\"python\">{ _id: 1, results: [ 82, 85, 88  ] } { _id: 2, results: [ 75, 88, 89 ] } db.test.find(   { results: { $elemMatch: { $gte: 80, $lt: 85 } } } ) <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"python\">{ _id: 1, results: [ 82, 85, 88 ] } <\/code><\/pre>\n<p>  \u0415\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">{ _id: 1, results: [{ product: &quot;abc&quot;, score: 10 }, { product: &quot;xyz&quot;, score: 5}] } { _id: 2, results: [{ product: &quot;abc&quot;, score: 8 }, { product: &quot;xyz&quot;, score: 7}] } { _id: 3, results: [{ product: &quot;abc&quot;, score: 7 }, { product: &quot;xyz&quot;, score: 8}] }  &gt;db.test.find(       { results: { $elemMatch: { product: &quot;xyz&quot;, score: { $gte: 8 } } } }  )  { &quot;_id&quot;: 3, &quot;results&quot;: [{ &quot;product&quot;: &quot;abc&quot;, &quot;score&quot;: 7 }, { &quot;product&quot;: &quot;xyz&quot;, &quot;score&quot;: 8 } ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$size \u0438\u0449\u0435\u0442 \u043f\u043e \u0434\u043b\u0438\u043d\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430<\/font><\/em><br \/>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>$size<\/code> \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0440\u0430\u0432\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e <code>$size<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043c \u0432\u0441\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 laguages \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:  <\/p>\n<pre><code class=\"python\">db.persons.find ({languages: {$size:2}}) <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443:  <\/p>\n<pre><code class=\"python\">{&quot;name&quot;: &quot;Alex&quot;, &quot;age&quot;: &quot;32&quot;, languages: [&quot;python&quot;, &quot;mongodb&quot;]} <\/code><\/pre>\n<p>  <em><font color=\"blue\">$ \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<\/font><\/em><br \/>  <code>$<\/code> \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u043c \u043f\u043e\u0434 \u043a\u0430\u043a\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u043b\u0435\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u043d\u043e \u0445\u043e\u0442\u0438\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u00ab\u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u00bb<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b:  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 3, &quot;semester&quot; : 1, &quot;grades&quot; : [ 85, 100, 90 ] } { &quot;_id&quot; : 4, &quot;semester&quot; : 2, &quot;grades&quot; : [ 79, 85, 80 ] } <\/code><\/pre>\n<p>  \u0418 \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u043d\u0438\u043c \u0432\u044b\u0432\u0435\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0443, \u0430 \u043d\u0435 \u0432\u0435\u0441\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442, \u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u043c \u043a\u0430\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u043c \u0441\u0442\u043e\u0438\u0442.  <\/p>\n<pre><code class=\"python\">&gt;db.test.find( { semester: 1, grades: { $gte: 85 } }, { &quot;grades.$&quot;: 1 } ) { &quot;_id&quot; : 3, &quot;grades&quot; : [ 85 ] } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f update:  <\/p>\n<pre><code class=\"python\">db.test.update( { _id: 22 } , { $set: { &quot;array.$.name&quot; : &quot;alex&quot; } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$slice \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d<\/font><\/em><br \/>  <code>$slice<\/code> \u2014 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435.<br \/>  \u041d\u0430\u0439\u0442\u0438 \u043f\u0435\u0440\u0432\u044b\u0435 10 \u0441\u043e\u0431\u044b\u0442\u0438\u0439:  <\/p>\n<pre><code class=\"python\">db.test.find( {  }, { &quot;events&quot; : { $slice: 10 }  }  ) <\/code><\/pre>\n<p>  \u041d\u0430\u0439\u0442\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 10 \u0441\u043e\u0431\u044b\u0442\u0438\u0439:  <\/p>\n<pre><code class=\"python\">db.test.find( {  }, { &quot;events&quot; : { $slice: -10 }  }  ) <\/code><\/pre>\n<h3><a name=\"1\"><\/a> <font color=\"green\"> \u041f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a, regexp, \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0438 \u043f\u0440.<\/font><\/h3>\n<p>  \u041d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0431\u044b\u043b\u0430 \u043d\u0435\u043f\u043b\u043e\u0445\u0430\u044f <a href=\"http:\/\/habrahabr.ru\/post\/174457\/\">\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f<\/a> \u043f\u0440\u043e \u043f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0432 <code>mongodb<\/code> \u043d\u043e \u0441 \u0442\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u043e\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438. <br \/>  \u0422\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043d\u0438\u0445. <br \/>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043b\u044e\u0431\u043e\u043c\u0443 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u0438\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0443.   <\/p>\n<pre><code class=\"python\">db.test.createIndex(  {  title: &quot;text&quot;,   content: &quot;text&quot;  }  ) <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0438\u043b\u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440:  <\/p>\n<pre><code class=\"python\">db.text.createIndex( { &quot;$**&quot;: &quot;text&quot; }  ) <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0434\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u044f\u0437\u044b\u043a, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439.  <\/p>\n<pre><code class=\"python\">db.test.createIndex( { content : &quot;text&quot; }, { default_language: &quot;russian&quot; } ) <\/code><\/pre>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.6<\/code> \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0441\u0440\u0430\u0437\u0443 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 \u0441 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441.<\/b><\/p>\n<div class=\"spoiler_text\">\n<ul>\n<li>da or danish<\/li>\n<li>nl or dutch<\/li>\n<li>en or english<\/li>\n<li>fi or finnish<\/li>\n<li>fr or french<\/li>\n<li>de or german<\/li>\n<li>hu or hungarian<\/li>\n<li>it or italian<\/li>\n<li>nb or norwegian<\/li>\n<li>pt or portuguese<\/li>\n<li>ro or romanian<\/li>\n<li>ru or russian<\/li>\n<li>es or spanish<\/li>\n<li>sv or swedish<\/li>\n<li>tr or turkish<\/li>\n<\/ul>\n<p>  <\/div>\n<\/div>\n<p>  <code>MongoDB<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u044f\u0437\u044b\u043a \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u042f\u0437\u044b\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u044f\u0437\u044b\u043a \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u042f\u0437\u044b\u043a \u0432\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430.  <\/p>\n<pre><code class=\"python\">{ _id: 1,    language: &quot;portuguese&quot;,    original: &quot;A sorte protege os audazes.&quot;,    translation: [         { language: &quot;english&quot;, quote: &quot;Fortune favors the bold.&quot; },         { language: &quot;russian&quot;, quote: &quot;\u0424\u043e\u0440\u0442\u0443\u043d\u0430 \u043b\u044e\u0431\u0438\u0442 \u0441\u043c\u0435\u043b\u044b\u0445.&quot; }     ]  } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>language_override<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u0441 \u044f\u0437\u044b\u043a\u043e\u043c.<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432:  <\/p>\n<pre><code class=\"python\">{ _id: 2, idioma: &quot;english&quot;, quote: &quot;Fortune favors the bold.&quot; } { _id: 3, idioma: &quot;russian&quot;, quote: &quot;\u0424\u043e\u0440\u0442\u0443\u043d\u0430 \u043b\u044e\u0431\u0438\u0442 \u0441\u043c\u0435\u043b\u044b\u0445.&quot; } <\/code><\/pre>\n<p>  \u0418\u043d\u0434\u0435\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"python\">db.text.createIndex( { quote : &quot;text&quot; },  { language_override: &quot;idioma&quot; } ) <\/code><\/pre>\n<p>  \u0418\u043d\u0434\u0435\u043a\u0441\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043c\u044f <code> { name: &quot;name&quot; } <\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">db.text.createIndex(  { content: &quot;text&quot;, &quot;users.title&quot;: &quot;text&quot; },  {   name: &quot;text_Index&quot;  }  ) <\/code><\/pre>\n<p>  \u0418\u043c\u044f \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432:  <\/p>\n<pre><code class=\"python\">db.text.dropIndex(&quot;text_Index&quot;) <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u044c, \u0432\u0435\u0441 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430.<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0432\u0435\u0441 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u043b\u0435\u0439: <code>content - 10<\/code>, <code>keywords - 5<\/code>, \u0438 <code>title - 1<\/code>.  <\/p>\n<pre><code class=\"python\">db.test.createIndex(          {  content: &quot;text&quot;, tags: &quot;text&quot;, title: &quot;text&quot; },         { weights: { content: 10, tags: 5, }, name: &quot;TextIndex&quot;} ) <\/code><\/pre>\n<p>  \u0427\u0435\u0440\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u043e\u0436\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043a\u043e\u043b-\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0432\u044b\u0434\u0430\u0447\u0435:  <\/p>\n<pre><code class=\"python\">{ _id: 1, dept: &quot;one&quot;, content: &quot;red&quot; } { _id: 3, dept: &quot;one&quot;, content: &quot;red&quot; } { _id: 2, dept: &quot;two&quot;, content: &quot;gren&quot; } db.test.createIndex( {  dept: 1,  content: &quot;text&quot;   } ) db.test.find( { dept: &quot;one&quot;, $text: { $search: &quot;green&quot; } } ) <\/code><\/pre>\n<p>  \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0432\u0443\u0445, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0438 \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0435.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0434\u043b\u044f <code>Python<\/code>:  <\/p>\n<pre><code class=\"python\">#PyMongo db.text.ensure_index( [ ('descr', &quot;text&quot; ), ( 'title.ru', &quot;text&quot; ) ], default_language=&quot;russian&quot;, name=&quot;full_text&quot;) <\/code><\/pre>\n<p>  <\/p>\n<h5>\u0422\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a<\/h5>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 mongodb \u043e\u043d \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u043b\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>runCommand<\/code> \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">db.collection.runCommand( &quot;text&quot;, { search: &quot;\u043c\u0435\u0447&quot; } ) <\/code><\/pre>\n<p>  \u043d\u043e, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.6<\/code>, \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em><font color=\"blue\">$text<\/font><\/em> <br \/>  \u041f\u043e\u0438\u0441\u043a \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u043b\u043e\u0432\u0443:  <\/p>\n<pre><code class=\"python\">db.articles.find( { $text: { $search: &quot;coffee&quot; } } ) <\/code><\/pre>\n<p>  \u041f\u043e\u0438\u0441\u043a \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u043b\u043e\u0432\u0430\u043c:  <\/p>\n<pre><code class=\"python\">db.articles.find( { $text: { $search: &quot;bake coffee cake&quot; } } ) <\/code><\/pre>\n<p>  \u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0444\u0440\u0430\u0437\u0435:  <\/p>\n<pre><code class=\"python\">db.articles.find( { $text: { $search: &quot;\\&quot;coffee cake\\&quot;&quot; } } ) <\/code><\/pre>\n<p>  \u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 \u043f\u043e\u0438\u0441\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 <em><font color=\"blue\">&#8212;<\/font><\/em>  <\/p>\n<pre><code class=\"python\">db.articles.find( { $text: { $search: &quot;bake coffee -cake&quot; } } ) <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0441 <code>mongodb 2.6<\/code> \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em><font color=\"blue\">$meta<\/font><\/em>, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.   <\/p>\n<pre><code class=\"python\">db.text.insert([ \t{ &quot;_id&quot;: 4,  &quot;descr&quot; : &quot;\u043d\u043e\u0432\u044b\u0439 \u043c\u0438\u0440\u043e\u0432\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot; }, \t{ &quot;_id&quot;: 3,  &quot;descr&quot; : &quot;\u043c\u044b \u0436\u0438\u0432\u0435\u043c \u0432 \u0441\u0442\u0440\u0430\u043d\u0435 \u0442\u0430\u043a\u043e\u0439-\u0442\u043e&quot; }, \t{ &quot;_id&quot;:6,   &quot;descr&quot; : &quot;\u043d\u043e\u0432\u044b\u0439 \u043c\u0438\u0440\u043e\u0432\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot; }, \t{ &quot;_id&quot;:7,   &quot;descr&quot; : &quot;\u043b\u0443\u0447\u0448\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0432 \u043c\u0438\u0440\u0435&quot; }, \t{ &quot;_id&quot;:8,   &quot;descr&quot; : &quot;\u0447\u0435\u0433\u043e \u0432\u0441\u0435 \u0445\u043e\u0442\u044f\u0442&quot; }, \t{ &quot;_id&quot;:9,   &quot;descr&quot; : &quot;\u0441\u0442\u0440\u0430\u043d\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0436\u0438\u0432\u0435\u043c&quot; }, \t{ &quot;_id&quot;:10, &quot;descr&quot; : &quot;\u0433\u043e\u0440\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0436\u0438\u0432\u0435\u043c&quot; }, \t{ &quot;_id&quot;:11, &quot;descr&quot; : &quot;\u0436\u0438\u0437\u043d\u044c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0441\u0432\u043e\u0438\u043c \u0447\u0435\u0440\u0435\u0434\u043e\u043c&quot; } \t{ &quot;_id&quot;:12, &quot;descr&quot; : &quot;\u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot; }, \t{ &quot;_id&quot;:13, &quot;descr&quot; : &quot;\u043f\u043b\u043e\u0445\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot; }, ]) db.text.createIndex( { descr : &quot;text&quot; }, { default_language: &quot;russian&quot; } ) db.text.find( { $text: { $search: &quot;\u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot; } },  { score: { $meta: &quot;textScore&quot; } }).sort( { score: { $meta: &quot;textScore&quot; } } )  { &quot;_id&quot; : 13, &quot;descr&quot; : &quot;\u043f\u043b\u043e\u0445\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot;, &quot;score&quot; : 0.75 } { &quot;_id&quot; : 4, &quot;descr&quot; : &quot;\u043d\u043e\u0432\u044b\u0439 \u043c\u0438\u0440\u043e\u0432\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot;, &quot;score&quot; : 0.6666666666666666 } { &quot;_id&quot; : 6, &quot;descr&quot; : &quot;\u043d\u043e\u0432\u044b\u0439 \u043c\u0438\u0440\u043e\u0432\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot;, &quot;score&quot; : 0.6666666666666666 } { &quot;_id&quot; : 12, &quot;descr&quot; : &quot;\u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a&quot;, &quot;score&quot; : 0.6666666666666666 } <\/code><\/pre>\n<p>  \u0422\u0443\u0442 <code> { score: { $meta: &quot;textScore&quot; } }<\/code> \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0432 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u043d\u043e \u0443\u0436\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435.<br \/>  <em><font color=\"blue\">\u041f\u043e\u0438\u0441\u043a \u0447\u0435\u0440\u0435\u0437 $regex<\/font><\/em><br \/>  <code>MongoDB<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>Perl<\/code>-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f.   <\/p>\n<pre><code class=\"python\">db.test.insert([     { &quot;_id&quot; : 1, &quot;descr&quot; : &quot;abc123&quot; },     { &quot;_id&quot; : 2, &quot;descr&quot; : &quot;abc123&quot; },     { &quot;_id&quot; : 3, &quot;descr&quot; : &quot;eee789&quot; } ]) db.test.find( { sku: { $regex: \/^ABC\/i } } ) { &quot;_id&quot; : 1, &quot;sku&quot; : &quot;abc123&quot;, &quot;description&quot; : &quot;Single line description.&quot; } { &quot;_id&quot; : 2, &quot;sku&quot; : &quot;abc123&quot;, &quot;description&quot; : &quot;Single line description.&quot; } <\/code><\/pre>\n<p>  <code>i<\/code> \u2014 \u041d\u0435\u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443.<br \/>  \u0410\u043d\u0430\u043b\u043e\u0433 \u0438\u0437 <code>PostgreSQL<\/code>  <\/p>\n<pre><code class=\"bash\">select title from article where title ~ '^a' 'abc' <\/code><\/pre>\n<h3><a name=\"1\"><\/a> <font color=\"green\"> \u0410\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b (\u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 ) <\/font><\/h3>\n<p>  \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432\u0441\u0435 \u044d\u0442\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432 <code>db.test.update()<\/code> \u0438 <code>db.test.findAndModify() <\/code><\/p>\n<p>  <em><font color=\"blue\">$inc \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442<\/font><\/em><br \/>  \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0438\u043b\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u043f\u043e\u043b\u0435 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435  <\/p>\n<pre><code class=\"python\">db.test.update( { _id: 1 }, { $inc: { qty: -2, &quot;orders&quot;: 1 } } ) <\/code><\/pre>\n<p>  <em><font color=\"blue\">$mul \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442<\/font><\/em><br \/>  \u0423\u043c\u043d\u043e\u0436\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443.  <\/p>\n<pre><code class=\"python\">{ _id: 5, item: &quot;mac&quot;, price: 10 } db.test.update({ _id: 1 }, { $mul: { price: 2 } } ) { _id: 5, item: &quot;mac&quot;, price : 20 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$rename \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f<\/font><\/em>  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot;: 1,   &quot;name&quot;: &quot;alex&quot; } db.test.update( { _id: 1 }, { $rename: { 'name': 'alias'} } ) { &quot;_id&quot;: 1,   &quot;alias&quot;: &quot;alex&quot; } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$set \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439<\/font><\/em><br \/>  \u041d\u0430\u0432\u0435\u0440\u043d\u043e \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>update<\/code>. \u0427\u0430\u0441\u0442\u043e \u043e \u043d\u0435\u043c \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u043a\u0430\u043a \u043e \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 mongodb.  <\/p>\n<pre><code class=\"python\">db.test.save({ &quot;_id&quot;:8,   &quot;qty&quot;:&quot;&quot;, tags:&quot;&quot; }) db.test.update( { _id: 8 }, { $set: { qty: 100, tags: [ &quot;linux&quot;, &quot;ubuntu&quot;]  } }) { &quot;_id&quot; : 8, &quot;qty&quot; : 100, &quot;tags&quot; : [ &quot;linux&quot;, &quot;ubuntu&quot; ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$setOnInsert \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044f \u0432 \u043d\u043e\u0432\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442<\/font><\/em><br \/>  \u0412 <code>update<\/code> \u0442\u0440\u0435\u0442\u044c\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0438\u0434\u0435\u0442 \u043e\u043f\u0446\u0438\u044f <code>{ upsert: true }<\/code> \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439. \u0410 \u043e\u043f\u0446\u0438\u044f <code>$setOnInsert<\/code> \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043d\u0430\u043c \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u0442\u0443\u0434\u0430 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c.  <\/p>\n<pre><code class=\"python\">&gt;db.test.update(       { _id: 7 }, { $set: { item: &quot;windows&quot; }, $setOnInsert: { os: 'bad' } }, { upsert: true } ) { &quot;_id&quot; : 7, &quot;item&quot; : &quot;windows&quot;, &quot;os&quot; : &quot;bad&quot; } <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0435, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <code>$set<\/code> \u0442\u043e\u0436\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435.<br \/>  <em><font color=\"blue\">$unset \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043a\u043b\u044e\u0447<\/font><\/em>  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 8, &quot;qty&quot; : 100, &quot;tags&quot; : [ &quot;linux&quot;, &quot;ubuntu&quot; ] } db.test.update( { _id: 8 }, { $unset:  { qty: &quot;&quot;,  tags: &quot;&quot;  } } ) { &quot;_id&quot; : 8 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$min \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442, \u0435\u0441\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435<\/font><\/em><br \/>  <code>$min<\/code> \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0435, \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f, <code>$min<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432.  <\/p>\n<pre><code class=\"python\">&gt; db.test.save({ _id: 9, high: 800, low: 200 }) &gt; db.test.update( { _id:9 }, { $min: { low: 150 } } ) &gt;db.test.findOne({_id:9}) { &quot;_id&quot; : 9, &quot;high&quot; : 800, &quot;low&quot; : 150 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$max \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0435\u0441\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435<\/font><\/em><br \/>  <code>$max<\/code> \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0435, \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f.  <\/p>\n<pre><code class=\"python\">&gt; db.test.save({ _id: 9, high: 800, low: 200 }) &gt; db.test.update( { _id:9 }, { $max: { low: 900 } } ) &gt; db.test.findOne({_id:9}) { &quot;_id&quot; : 9, &quot;high&quot; : 900, &quot;low&quot; : 150 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$currentDate \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0434\u0430\u0442\u0443<\/font><\/em><br \/>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0434\u0430\u0442\u0443.  <\/p>\n<pre><code class=\"python\">&gt; db.test.save({ _id:11, status: &quot;init&quot;, date: ISODate(&quot;2015-05-05T01:11:11.111Z&quot;) }) &gt; db.test.update( { _id:12 },  { $currentDate: { date: true } } ) &gt; db.test.findOne({_id:12}) { &quot;_id&quot; : 12, &quot;status&quot; : &quot;a&quot;, &quot;date&quot; : ISODate(&quot;2015-05-10T21:07:31.138Z&quot;) } <\/code><\/pre>\n<p>  <\/p>\n<h5>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432<\/p>\n<h5><em><font color=\"blue\">$addToSet \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442<\/font><\/em><br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0442\u0430\u043c \u0435\u0449\u0435 \u043d\u0435\u0442, \u0430 \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442.  <\/p>\n<pre><code class=\"python\">&gt; db.test.save({ _id:1, array: [&quot;a&quot;, &quot;b&quot;] }) &gt; db.test.update( { _id: 1 }, { $addToSet: {array: [ &quot;c&quot;, &quot;d&quot; ] } } ) { &quot;_id&quot; : 1, &quot;array&quot; : [ &quot;a&quot;, &quot;b&quot;, [ &quot;c&quot;, &quot;d&quot; ] ] } &gt; db.test.update( { _id: 1 }, { $addToSet: {array: &quot;e&quot;  } } ) { &quot;_id&quot; : 1, &quot;array&quot; : [ &quot;a&quot;, &quot;b&quot;, [ &quot;c&quot;, &quot;d&quot; ], &quot;e&quot; ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$pop \u0443\u0434\u0430\u043b\u044f\u0435\u0442 1-\u0439 \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439<\/font><\/em><br \/>  \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0415\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043e -1 \u0442\u043e \u0443\u0434\u0430\u043b\u0438\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043e 1, \u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439.  <\/p>\n<pre><code class=\"python\">&gt; db.test.save({ _id: 1, scores: [ 6, 7, 8, 9, 10 ] }) { &quot;_id&quot; : 1, &quot;scores&quot; : [ 6, 7, 8, 9, 10 ] } &gt; db.test.update( { _id: 1 }, { $pop: { scores: -1 } } ) &gt; db.test.findOne({_id:1}) { &quot;_id&quot; : 1, &quot;scores&quot; : [ 7, 8, 9, 10 ] } &gt; db.test.update( { _id: 1 }, { $pop: { scores: 1 } } ) &gt; db.test.findOne({_id:1}) { &quot;_id&quot; : 1, &quot;scores&quot; : [ 7, 8, 9 ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$pullAll \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435<\/font><\/em><br \/>  \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.  <\/p>\n<pre><code class=\"python\">{ _id: 1, scores: [ 0, 2, 5, 5, 1, 0 ] } db.test.update( { _id: 1 }, { $pullAll: { scores: [ 0, 5 ] } } ) { &quot;_id&quot; : 1, &quot;scores&quot; : [ 2, 1 ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$pull \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c<\/font><\/em>  <\/p>\n<pre><code class=\"python\">{ _id: 1, votes: [ 3, 5, 6, 7, 7, 8 ] } &gt; db.test.update( { _id: 1 }, { $pull: { votes: { $gte: 6 } } } ) { _id: 1, votes: [  3,  5 ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$push \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/font><\/em><br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432.  <\/p>\n<pre><code class=\"python\">db.test.update( { _id: 1 }, { $push: { scores: 100} } ) <\/code><\/pre>\n<p>  <code>$pushAll<\/code> \u2014 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u043c  <\/p>\n<h5>\u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f $push<\/p>\n<h5><em><font color=\"blue\">$each \u0441\u0440\u0430\u0437\u0443 \u043c\u043d\u043e\u0433\u043e<\/font><\/em><br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a: <code>{ $push: { scores:  [  2, 10 ] } }<\/code><br \/>  \u0422\u043e \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432: <code>&quot;scores&quot; : [7, 8, 9, 90, 92, 85, [ 2, 10 ] ] <\/code><br \/>  \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c.<br \/>  \u0410 \u0435\u0441\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 <code>$each<\/code>, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u0430\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430:  <\/p>\n<pre><code class=\"python\">&gt; db.test.update( { _id: 1 }, { $push: {scores: { $each: [ 90, 92, 85 ] } } }  ) {&quot;_id&quot; : 1, &quot;scores&quot; : [7, 8, 9, 90, 92, 85, 2, 10  ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$slice \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 $push<\/font><\/em><br \/>  \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u0440\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>$push<\/code>. \u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>$each<\/code> \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0437 \u043d\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443.  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;scores&quot; : [ 10, 20, 30 ] } &gt; db.test.update( { _id: 1 },  {  $push: {  scores: {  $each: [ 50, 60, 70 ],   $slice: -5    }  }  } ) { &quot;_id&quot; : 1, &quot;scores&quot; : [  20,  30,  50,  60,  70 ] } <\/code><\/pre>\n<p>  <code>$slice<\/code> \u043e\u0442\u0440\u0435\u0437\u0430\u043b \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>20<\/code>. \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u043d\u0435 <code>-5<\/code> \u0430 <code>5<\/code> \u0442\u043e \u043e\u043d \u0431\u044b \u043e\u0442\u043a\u0438\u043d\u0443\u043b \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>70<\/code>.<\/p>\n<p>  <em><font color=\"blue\">$sort \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430<\/font><\/em><br \/>  \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u0435\u043c. \u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>$each<\/code>. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u0432\u0441\u0442\u0430\u0432\u043a\u0438, \u0442\u043e <code>$each<\/code> \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c.  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 2, &quot;tests&quot; : [  80,  70,  80,  50 ] } &gt; db.test.update( { _id: 2 }, { $push: { tests: { $each: [ 40, 60 ], $sort: 1 } } }    ) { &quot;_id&quot; : 2, &quot;tests&quot; : [  40,  50,  60,  70,  80,  80 ] } <\/code><\/pre>\n<p>  \u0415\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">db.test.update( { _id: 1 }, { $push: {  field: {  $each: [ ], $sort: { score: 1 }  }  }  } ) {  &quot;_id&quot; : 1, &quot;field&quot; : [       { &quot;id&quot; : 3, &quot;score&quot; : 5 },      { &quot;id&quot; : 2, &quot;score&quot; : 6 },      { &quot;id&quot; : 1, &quot;score&quot; : 7 },   ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$position \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0432\u0441\u0442\u0430\u0432\u043a\u0438<\/font><\/em><br \/>  \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441 \u043a\u0430\u043a\u043e\u0433\u043e \u043f\u043e \u0441\u0447\u0435\u0442\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;scores&quot; : [ 100 ] } db.test.update({ _id: 1 }, {$push: { scores: { $each: [50, 60, 70], $position: 0 } } }) { &quot;_id&quot; : 1, &quot;scores&quot; : [  50,  60,  70,  100 ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$bit \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442<\/font><\/em><br \/>  \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0435 <code>and<\/code>, <code>or<\/code> \u0438 <code>xor<\/code>.  <\/p>\n<pre><code class=\"python\">{ &quot;_id&quot; : 1, &quot;expdata&quot; : 13 } &gt; db.bit.update({_id:1}, {$bit:{expdata:{and:NumberInt(10)} } } ) { &quot;_id&quot; : 1, &quot;expdata&quot; : 8 } <\/code><\/pre>\n<p>  <em><font color=\"blue\">$isolated \u2014 \u0430\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u044f<\/font><\/em><br \/>  \u0411\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438, \u043f\u043e\u043a\u0430 \u0441 \u043d\u0438\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>$isolated<\/code> \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438:  <\/p>\n<pre><code class=\"python\">db.test.remove( { temp: { $lt: 10 }, $isolated: 1 } ) <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>$isolated<\/code> \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438:  <\/p>\n<pre><code class=\"python\">db.test.update( { status : &quot;init&quot; , $isolated : 1 },  { $inc : { count : 1 } },  { multi: true } ) <\/code><\/pre>\n<p>  <i>$isolated \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c\u0438<\/i><br \/>  \u0421 \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.2<\/code>: \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>$isolated<\/code> \u0437\u0430\u043c\u0435\u043d\u0438\u043b <code>$atomic<\/code><\/p>\n<h3><a name=\"5\"><\/a> <font color=\"green\">\u041e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445 \u0432 mongodb, \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441, \u0434\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u043c\u043c\u0438\u0442<\/font><\/h3>\n<p>  \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0438\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043a\u0430\u043a \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 <code>SQL<\/code> \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u0442\u0438\u043f\u0430 <code>PostgreeSQL<\/code> \u0432 <code>MongoDB<\/code> \u043d\u0435\u0442 \u0438 \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c. \u0410 \u0435\u0441\u043b\u0438 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0436\u0435, \u0441\u043a\u043e\u0440\u0435\u0435, \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0433\u043e\u0432\u043e\u0440\u044f \u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445 \u0432 <code>mongoDB<\/code>, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0438\u043c\u0435\u044e\u0442 \u0432 \u0432\u0438\u0434\u0443 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u0430 <code>$set<\/code>, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0432 <code>update()<\/code> \u0438 <code>findAndModify()<\/code> \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0434\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u043c\u043c\u0438\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d \u0441\u0440\u0435\u0434\u0438 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0431\u0430\u0437. <\/p>\n<h3><a name=\"51\"><\/a> <font color=\"blue\">\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/font><\/h3>\n<p>  \u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0432 <code>mongodb<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.  <\/p>\n<pre><code class=\"python\">db.test.createIndex( { &quot;user_id&quot;: 1 }, { unique: true } ) <\/code><\/pre>\n<p>  \u0415\u0441\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f, \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0451 <code>test<\/code>, \u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043d\u0435\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0435 <code>name<\/code> \u0438\u043c\u0435\u043b\u043e \u0431\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>Nik<\/code>. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>{ upsert: true }<\/code> (\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f, \u0442\u043e \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c).<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">db.test.update( { name: &quot;Nik&quot; }, { name: &quot;Nik&quot;, vote: 1 }, { upsert: true } ) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 <code>update()<\/code> \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043d\u0430\u0448\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u0441\u0432\u043e\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438 \u043d\u0435\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043d\u0430 \u043f\u043e\u043b\u0435, \u0442\u043e \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0432 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 \u043f\u043e\u043b\u0435. \u0422\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u0442\u043e\u0447\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u043d\u043e\u0432\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043b\u0438\u0431\u043e \u043e\u0431\u043d\u043e\u0432\u044f\u0442 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442, \u043b\u0438\u0431\u043e \u043d\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>unique<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>false<\/code> \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445 <code>MongoDB<\/code><\/p>\n<h3><a name=\"52\"><\/a> <font color=\"blue\">\u0414\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u043c\u043c\u0438\u0442<\/font><\/h3>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0443 \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0441\u043e \u0441\u0447\u0435\u0442\u0430 <code>A<\/code> \u043d\u0430 \u0441\u0447\u0435\u0442 <code>B<\/code>.<br \/>  \u0423 \u043d\u0430\u0441 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438:  <\/p>\n<ul>\n<li>\u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f <code>accounts<\/code> \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0447\u0435\u0442\u0430 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/li>\n<li>\u0418 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f <code>transactions<\/code> \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445. <\/li>\n<\/ul>\n<p>  <em><font color=\"blue\">\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 accounts \u0438 transactions<\/font><\/em><br \/>  \u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e <code>accounts<\/code> \u0434\u0432\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0441\u0447\u0435\u0442\u043e\u0432 <code>\u0410<\/code> \u0438 <code>\u0412<\/code>  <\/p>\n<pre><code class=\"python\">db.accounts.insert(    [      { _id: &quot;A&quot;, balance: 1000, pendingTransactions: [] },      { _id: &quot;B&quot;, balance: 1000, pendingTransactions: [] }    ] ) <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e <code>transactions<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.  <\/p>\n<pre><code class=\"python\">db.transactions.insert({ _id: 1, source: &quot;A&quot;, destination: &quot;B&quot;, value: 100, state: &quot;initial&quot;, lastModified: new Date()}) <\/code><\/pre>\n<p>  \u0413\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f:  <\/p>\n<ul>\n<li>\u041f\u043e\u043b\u044f <code>source<\/code> \u0438 <code>destination<\/code> \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0441\u0447\u0435\u0442 \u0438 \u0441\u0447\u0435\u0442 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430.<\/li>\n<li>\u041f\u043e\u043b\u0435 <code>value<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0443\u043c\u043c\u0443 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c \u0441\u043e \u0441\u0447\u0435\u0442\u0430 \u043d\u0430 \u0441\u0447\u0435\u0442.<\/li>\n<li>\u041f\u043e\u043b\u0435 <code>state<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0441\u0442\u0430\u0442\u0443\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u041c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <code>initial<\/code>, <code>pending<\/code>, <code>applied<\/code>, <code>done<\/code>, <code>canceling<\/code>, \u0438 <code>canceled<\/code>.<\/li>\n<li><code>lastModified<\/code> \u043f\u043e\u043b\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/li>\n<\/ul>\n<p>  <em><font color=\"blue\">1) \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0435\u0439 <\/font><\/em><br \/>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0435\u0439, \u0438\u043c\u0435\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 <code>initial<\/code>. \u0418 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>t<\/code>   <\/p>\n<pre><code class=\"bash\">&gt; var t = db.transactions.findOne( { state: &quot;initial&quot; } ) &gt; t { &quot;_id&quot; : 1, &quot;source&quot; : &quot;A&quot;, \t&quot;destination&quot; : &quot;B&quot;, &quot;value&quot; : 100, &quot;state&quot; : &quot;initial&quot;, &quot;lastModified&quot; : ISODate(&quot;2015-05-26T16:35:54.637Z&quot;) } <\/code><\/pre>\n<p>  <em><font color=\"blue\">2) \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0434\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f pending<\/font><\/em><br \/>  \u041c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0441 <code>initial<\/code> \u043d\u0430 <code>pending<\/code> \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0434\u0430\u0442\u0443.  <\/p>\n<pre><code class=\"python\">&gt; db.transactions.update(     { _id: t._id, state: &quot;initial&quot; },     { $set: { state: &quot;pending&quot; }, $currentDate: { lastModified: true } } ) &gt; db.transactions.find() { &quot;_id&quot; : 1, &quot;source&quot; : &quot;A&quot;, &quot;destination&quot; : &quot;B&quot;, &quot;value&quot; : 100, &quot;state&quot; : &quot;pending&quot;, &quot;lastModified&quot; : ISODate(&quot;2015-05-26T17:02:19.002Z&quot;) } &gt;  <\/code><\/pre>\n<p>  <em><font color=\"blue\">3) \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u043e\u0438\u0445 \u0441\u0447\u0435\u0442\u043e\u0432<\/font><\/em><br \/>  \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0431\u0430\u043b\u0430\u043d\u0441 \u0443 \u043e\u0431\u043e\u0438\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430, \u043e\u0434\u043d\u043e\u043c\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u0440\u0430\u0432\u043d\u043e\u0435 \u043f\u043e\u043b\u044e <code>value<\/code> \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u0430 \u0432 \u043f\u043e\u043b\u0435 <code>pendingTransactions<\/code> \u0437\u0430\u043d\u043e\u0441\u0438\u043c <code>_id<\/code> \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438).  <\/p>\n<pre><code class=\"python\">&gt; db.accounts.update(    { _id: t.source, pendingTransactions: { $ne: t._id } },    { $inc: { balance: -t.value }, $push: { pendingTransactions: t._id } } )  &gt; db.accounts.update(    { _id: t.destination, pendingTransactions: { $ne: t._id } },    { $inc: { balance: t.value }, $push: { pendingTransactions: t._id } } )  &gt; db.accounts.find() { &quot;_id&quot; : &quot;A&quot;, &quot;balance&quot; : 900,   &quot;pendingTransactions&quot; : [ 1 ] } { &quot;_id&quot; : &quot;B&quot;, &quot;balance&quot; : 1100, &quot;pendingTransactions&quot; : [ 1 ] } <\/code><\/pre>\n<p>  <em><font color=\"blue\">4) \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0434\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f applied<\/font><\/em><br \/>  \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0435\u0439 \u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0430\u0442\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.  <\/p>\n<pre><code class=\"python\">&gt; db.transactions.update(    { _id: t._id, state: &quot;pending&quot; },    { $set: { state: &quot;applied&quot; }, $currentDate: { lastModified: true } } ) &gt; db.transactions.find() { &quot;_id&quot; : 1, &quot;source&quot; : &quot;A&quot;, &quot;destination&quot; : &quot;B&quot;, &quot;value&quot; : 100, &quot;state&quot; : &quot;applied&quot;, &quot;lastModified&quot; : ISODate(&quot;2015-05-26T17:13:15.517Z&quot;) } <\/code><\/pre>\n<p>  <em><font color=\"blue\">5) \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 _id \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438\u0437 \u043e\u0431\u043e\u0438\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/font><\/em><br \/>  \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043e\u0431\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e <code>pendingTransactions<\/code>: <code>_id<\/code> \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438 \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0443 \u043d\u0438\u0445 \u043f\u043e\u043b\u0435 <code>pendingTransactions<\/code>.  <\/p>\n<pre><code class=\"python\">&gt; db.accounts.update(    { _id: t.source, pendingTransactions: t._id },    { $pull: { pendingTransactions: t._id } } ) &gt; db.accounts.update(    { _id: t.destination, pendingTransactions: t._id },    { $pull: { pendingTransactions: t._id } } )  &gt; db.accounts.find() { &quot;_id&quot; : &quot;A&quot;, &quot;balance&quot; : 900, &quot;pendingTransactions&quot; : [ ] } { &quot;_id&quot; : &quot;B&quot;, &quot;balance&quot; : 1100, &quot;pendingTransactions&quot; : [ ] }   <\/code><\/pre>\n<p>  <em><font color=\"blue\">6) \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0434\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f done<\/font><\/em><br \/>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0434\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u043c\u043c\u0438\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d.  <\/p>\n<pre><code class=\"python\">&gt; db.transactions.update(    { _id: t._id, state: &quot;applied&quot; },    { $set: { state: &quot;done&quot; },  $currentDate: { lastModified: true }  } ) &gt; db.transactions.find() { &quot;_id&quot; : 1, &quot;source&quot; : &quot;A&quot;, &quot;destination&quot; : &quot;B&quot;, &quot;value&quot; : 100, &quot;state&quot; : &quot;done&quot;, &quot;lastModified&quot; : ISODate(&quot;2015-05-26T17:22:22.194Z&quot;) } <\/code><\/pre>\n<h5>\u041e\u0442\u043a\u0430\u0442 \u0434\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0438\u0442\u0430<\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439 \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u043d\u0435\u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0432\u0448\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c.<br \/>  <em><font color=\"blue\">1) \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 canceling <\/font><\/em><br \/>  \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0438, \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <code>canceling<\/code>.  <\/p>\n<pre><code class=\"python\">db.transactions.update(    { _id: t._id, state: &quot;pending&quot; },     {$set: { state: &quot;canceling&quot; }, $currentDate: { lastModified: true }} ) &gt; db.transactions.find() { &quot;_id&quot; : 1, &quot;source&quot; : &quot;A&quot;, &quot;destination&quot; : &quot;B&quot;, &quot;value&quot; : 100, &quot;state&quot; : &quot;canceling&quot;, &quot;lastModified&quot; : ISODate(&quot;2015-05-26T18:29:28.018Z&quot;) } <\/code><\/pre>\n<p>  <em><font color=\"blue\">2) \u041e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0441\u0447\u0435\u0442\u043e\u0432<\/font><\/em><br \/>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0441\u0447\u0435\u0442 \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043b\u0438.  <\/p>\n<pre><code class=\"python\">&gt; db.accounts.update(    { _id: t.destination, pendingTransactions: t._id },    {  $inc: { balance: -t.value }, $pull: { pendingTransactions: t._id }  } ) &gt; db.accounts.update(    { _id: t.source, pendingTransactions: t._id },    { $inc: { balance: t.value}, $pull: { pendingTransactions: t._id } } )  &gt; db.accounts.find() { &quot;_id&quot; : &quot;A&quot;, &quot;balance&quot; : 1000, &quot;pendingTransactions&quot; : [ 1 ] } { &quot;_id&quot; : &quot;B&quot;, &quot;balance&quot; : 1000, &quot;pendingTransactions&quot; : [ 1 ] } &gt;  <\/code><\/pre>\n<p>  <em><font color=\"blue\">3) \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 cancelled<\/font><\/em><br \/>  \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0439 \u0434\u043e \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u043d\u043e\u0439.  <\/p>\n<pre><code class=\"python\">db.transactions.update(    { _id: t._id, state: &quot;canceling&quot; },    { $set: { state: &quot;cancelled&quot; }, $currentDate: { lastModified: true } } ) &gt; db.transactions.find() { &quot;_id&quot; : 1, &quot;source&quot; : &quot;A&quot;, &quot;destination&quot; : &quot;B&quot;, &quot;value&quot; : 100, &quot;state&quot; : &quot;cancelled&quot;, &quot;lastModified&quot; : ISODate(&quot;2015-05-26T19:14:11.830Z&quot;) } <\/code><\/pre>\n<h5>\u0414\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u043c\u043c\u0438\u0442 \u0438 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/h5>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0432\u0430\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u043b\u043e\u0441\u044c \u043a \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e\u0436\u0435 \u0432\u0440\u0435\u043c\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043a\u0440\u043e\u043c\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u043b \u0435\u0449\u0435 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<br \/>  \u0422\u0430\u043a\u0436\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>findAndModify()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u043d\u0435\u0439 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043e\u0434\u0438\u043d \u0448\u0430\u0433:<\/p>\n<pre><code class=\"python\">t = db.transactions.findAndModify({    query:  { state: &quot;initial&quot;, application: { $exists: false } },    update: {$set: { state: &quot;pending&quot;, application: &quot;App1&quot;}, $currentDate:{ lastModified: true }},    new: true  }) <\/code><\/pre>\n<h3><a name=\"6\"><\/a> <font color=\"green\">6. \u0410\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438 JOIN-\u044b<\/font><\/h3>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043f\u0440\u043e <code>JOIN<\/code>-\u044b \u0432 <code>mongo<\/code> \u0438\u043b\u0438 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442 \u043f\u0440\u043e \u043d\u0438\u0445, \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u0440\u0435\u0447\u044c \u0437\u0430\u0445\u043e\u0434\u0438\u0442 \u043e \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439. \u0427\u0430\u0441\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043c\u0435\u043b\u044c\u043a\u0430\u044e\u0442 \u043d\u0430 <code>stackoverflow<\/code>, \u043d\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. <\/p>\n<p>  \u0418, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435, \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e. <\/p>\n<p>  \u0410 \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u043e\u043c \u0435\u0441\u0442\u044c \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0438\u0445 \u043d\u0430 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c, \u0442\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u0438\u0445 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u043f\u043e\u043b\u0435\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>{ type: 'news' }<\/code>.<\/p>\n<p>  \u041d\u043e \u0431\u044b\u0432\u0430\u044e\u0442 \u0441\u043b\u0443\u0447\u0430\u0438 \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0434\u043e \u0432\u0437\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0431\u0449\u0435\u0433\u043e, \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u0445 \u0432 \u043e\u0434\u0438\u043d \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442.<\/p>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0442 \u0438 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0438\u0431\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043b\u0438\u0431\u043e \u043b\u0435\u043f\u0438\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0432 <code>aggregation framework<\/code>. \u041d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0436\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 <code>pipeline<\/code>. \u0412\u043e\u043e\u0431\u0449\u0435, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u0440\u043e\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u043b\u044e\u0431\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c, \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c, \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0442.\u0434.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0432 \u043e\u0434\u043d\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f.  <\/p>\n<pre><code class=\"python\">db.test.insert([      { &quot;_id&quot;:&quot;gomer&quot;, &quot;type&quot;:&quot;user&quot;, &quot;group&quot;:[&quot;user&quot;, &quot;author&quot;] },      { &quot;_id&quot;:&quot;vasya&quot;, &quot;type&quot;:&quot;user&quot;, &quot;group&quot;:[&quot;user&quot;] } ]) <\/code><\/pre>\n<p>  \u0418 \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u044d\u0442\u0438\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.  <\/p>\n<pre><code class=\"python\">db.test.insert([     { &quot;_id&quot;: 1,  &quot;type&quot;: &quot;blogs&quot;, &quot;user&quot;: &quot;gomer&quot;, &quot;article&quot;: &quot;aaa&quot; },     { &quot;_id&quot;: 2,  &quot;type&quot;: &quot;blogs&quot;, &quot;user&quot;: &quot;vasya&quot;, &quot;article&quot;:  &quot;bbb&quot; },     { &quot;_id&quot;: 3,  &quot;type&quot;: &quot;blogs&quot;, &quot;user&quot;: &quot;gomer&quot;, &quot;article&quot;: &quot;ccc&quot; } ]) <\/code><\/pre>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0441\u0442\u0430\u0442\u044c\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u0438\u0442. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u0442\u043e \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>  \u0412\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u0431\u043b\u043e\u0433\u043e\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0433\u0434\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0432\u0448\u0438\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b, \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0433\u0440\u0443\u043f\u043f\u0435 \u00ab\u0430\u0432\u0442\u043e\u0440\u00bb.  <\/p>\n<pre><code class=\"python\">users = [doc._id for doc in db.test.find({&quot;type&quot;:'user', 'group': {'$all': ['author']}})] articles = db.test.find({&quot;type&quot;: &quot;blogs&quot;, &quot;user&quot;: {'$in': users}) <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 c \u0434\u0436\u043e\u0439\u043d\u043e\u043c \u0438\u0437 SQL \u0435\u0441\u043b\u0438 \u043c\u044b \u0447\u043b\u0435\u043d\u0441\u0442\u0432\u043e \u0432 \u0433\u0440\u0443\u043f\u043f\u0430\u0445 \u0445\u0440\u0430\u043d\u0438\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435:  <\/p>\n<pre><code class=\"python\">SELECT  \tblogs.* FROM \tblogs, user, usergroup, group WHERE   blogs.user = user.id AND usergroup.user = user.id AND usergroup.group = group.id AND group.name = 'author'; <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0433\u0440\u0443\u043f\u043f \u0445\u0440\u0430\u043d\u0438\u043c \u043f\u0440\u044f\u043c\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 user, \u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u0435 d \u0442\u0438\u043f\u0430 jsonb. \u0421\u0435\u043b\u0435\u043a\u0442\u0430\u043c\u0438 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u0432\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u2014 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043d\u0430 \u043d\u0438\u0445 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u0442\u0435 \u0436\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:  <\/p>\n<pre><code class=\"sql\">SELECT blogs.* FROM blogs, user WHERE blogs.user = user.id AND user.group ? 'author'; SELECT blogs.* FROM  \t(SELECT * FROM test WHERE d-&gt;type = 'blogs') blogs,  \t(SELECT * FROM test WHERE d-&gt;type = 'user') user WHERE blogs.d-&gt;user = user.id AND user.d-&gt;group ? 'author'; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pipe.  <\/p>\n<pre><code class=\"python\">db.test.aggregate([ \t{ $match:  { $or: [ {type: &quot;blogs&quot;}, {type: &quot;user&quot;} ] } },   \t{ $project: {  \t\t\ta: 1, \t\t\tblogs: { \t\t\t\t$cond: { \t\t\t\t\tif: { type: '$blogs'}, \t\t\t\t\tthen: {_id:&quot;$_id&quot;, user:&quot;$user&quot;, article:&quot;$article&quot;}, \t\t\t\t\telse: null \t\t\t\t} \t\t\t}, \t\t\tuser: { \t\t\t\t$cond: { \t\t\t\t\tif: { type: '$user' }, \t\t\t\t\tthen: { _id:&quot;$_id&quot;, group:&quot;$group&quot;}, \t\t\t\t\telse: null \t\t\t\t} \t\t\t} \t\t} \t}, \t{ $group : { \t           _id : { a: &quot;$a&quot; }, \t           user: { $push: &quot;$user&quot; }, \t           blog: { $push: &quot;$blogs&quot; }, \t        } \t}, \t{ $unwind : &quot;$blog&quot; }, \t{ $unwind : &quot;$user&quot; }, \t{ $project:{  \t\tuser: &quot;$user&quot;, \t\tarticle: &quot;$blog&quot;, \t\tmatches: { $eq:[ &quot;$user._id&quot;, &quot;$blog.user&quot; ] } } \t},  \t{ $match: { matches: true } } ]) <\/code><\/pre>\n<p>   \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441. \u0417\u0430\u043f\u0440\u043e\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 7 \u0447\u0430\u0441\u0442\u0435\u0439. <br \/>  \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0432 \u0441\u043f\u0440\u0430\u0432\u043a\u0435 \u043f\u043e <code>mongodb<\/code> \u0438 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043f\u0440\u043e <code>pipeline<\/code> \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u044d\u0442\u0443 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443. \u041e\u043d\u0430 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u043d\u043e, \u0438\u043c\u0435\u044f \u0435\u0451 \u043f\u0435\u0440\u0435\u0434 \u0433\u043b\u0430\u0437\u0430\u043c\u0438, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u043a\u0430\u0445, \u043d\u0443 \u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043b\u044e\u0431\u043e\u0439 \u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437.   <\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td><font color=\"goldenrod\">WHERE<\/font><\/td>\n<td><font color=\"YellowGreen\">$match<\/font><\/td>\n<\/tr>\n<tr>\n<td><font color=\"goldenrod\">GROUP BY<\/font><\/td>\n<td><font color=\"YellowGreen\">$group<\/font><\/td>\n<\/tr>\n<tr>\n<td><font color=\"goldenrod\">HAVING<\/font><\/td>\n<td><font color=\"YellowGreen\">$match<\/font><\/td>\n<\/tr>\n<tr>\n<td><font color=\"goldenrod\">SELECT<\/font><\/td>\n<td><font color=\"YellowGreen\">$project<\/font><\/td>\n<\/tr>\n<tr>\n<td><font color=\"goldenrod\">ORDER BY<\/font><\/td>\n<td><font color=\"YellowGreen\">$sort<\/font><\/td>\n<\/tr>\n<tr>\n<td><font color=\"goldenrod\">LIMIT<\/font><\/td>\n<td><font color=\"YellowGreen\">$limit<\/font><\/td>\n<\/tr>\n<tr>\n<td><font color=\"goldenrod\">SUM()<\/font><\/td>\n<td><font color=\"YellowGreen\">$sum<\/font><\/td>\n<\/tr>\n<tr>\n<td><font color=\"goldenrod\">COUNT()<\/font><\/td>\n<td><font color=\"YellowGreen\">$sum<\/font><\/td>\n<\/tr>\n<tr>\n<td><font color=\"goldenrod\">join<\/font><\/td>\n<td> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <font color=\"YellowGreen\">$unwind<\/font><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.  <\/p>\n<pre><code class=\"python\">&gt; db.ag.aggregate([ { $match:   {$or:[{type:&quot;blogs&quot;},{type:&quot;user&quot;}]} }  ]) { &quot;_id&quot; : &quot;gomer&quot;, &quot;type&quot; : &quot;user&quot;, &quot;group&quot; : [ &quot;user&quot;, &quot;author&quot; ] } { &quot;_id&quot; : &quot;vasya&quot;, &quot;type&quot; : &quot;user&quot;, &quot;group&quot; : [ &quot;user&quot; ] } { &quot;_id&quot; : 1, &quot;type&quot; : &quot;blogs&quot;, &quot;user&quot; : &quot;gomer&quot;, &quot;article&quot; : &quot;aaa&quot; } { &quot;_id&quot; : 2, &quot;type&quot; : &quot;blogs&quot;, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; } { &quot;_id&quot; : 3, &quot;type&quot; : &quot;blogs&quot;, &quot;user&quot; : &quot;gomer&quot;, &quot;article&quot; : &quot;ccc&quot; } <\/code><\/pre>\n<p>  \u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>$match<\/code> \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 <code>find()<\/code>, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0435\u0433\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0443.<br \/>  \u0414\u0430\u043b\u044c\u0448\u0435 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>$project<\/code> \u043c\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 <code>blogs<\/code> \u0438 <code>users<\/code>. \u0422\u0430\u043c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 <code>2.6<\/code> \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>$cond<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u0438\u043f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0438 \u0443\u0436\u0435 \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u043b\u044f <code>blogs<\/code> \u0438 <code>users<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c.  <\/p>\n<pre><code class=\"python\">db.test.aggregate([ \t{ $match:   {$or:[ { type:&quot;blogs&quot;}, { type: &quot;user&quot;} ] } },   \t{ $project: {  \t\t\ta: 1, \t\t\tblogs: { \t\t\t\t$cond: { \t\t\t\t\tif: {type: '$blogs'}, \t\t\t\t\tthen: {_id:&quot;$_id&quot;, user:&quot;$user&quot;, article:&quot;$article&quot;}, \t\t\t\t\telse: null \t\t\t\t} \t\t\t}, \t\t\tuser: { \t\t\t\t$cond: { \t\t\t\t\tif: { type: '$user'}, \t\t\t\t\tthen: {_id:&quot;$_id&quot;, group:&quot;$group&quot;}, \t\t\t\t\telse: null \t\t\t\t} \t\t\t} \t\t} \t} ]) { &quot;_id&quot;: &quot;gomer&quot;, &quot;blogs&quot;: { &quot;_id&quot; : &quot;gomer&quot; }, &quot;user&quot;: { &quot;_id&quot;: &quot;gomer&quot;, &quot;group&quot;: [ &quot;user&quot;, &quot;author&quot; ] } } { &quot;_id&quot;: &quot;vasya&quot;, &quot;blogs&quot;: { &quot;_id&quot; : &quot;vasya&quot; }, &quot;user&quot; : { &quot;_id&quot; : &quot;vasya&quot;, &quot;group&quot;: [ &quot;user&quot; ] } } { &quot;_id&quot;: 1, &quot;user&quot;: { &quot;_id&quot;: 1 }, &quot;blogs&quot; : { &quot;_id&quot;: 1, &quot;user&quot;: &quot;gomer&quot;, &quot;article&quot;: &quot;aaa&quot; } } { &quot;_id&quot;: 2, &quot;user&quot;: { &quot;_id&quot;: 2 }, &quot;blogs&quot; : { &quot;_id&quot;: 2, &quot;user&quot;: &quot;vasya&quot;, &quot;article&quot;: &quot;bbb&quot; } } { &quot;_id&quot;: 3, &quot;user&quot;: { &quot;_id&quot;: 3 }, &quot;blogs&quot; : { &quot;_id&quot;: 3, &quot;user&quot;: &quot;gomer&quot;, &quot;article&quot;: &quot;ccc&quot; } } <\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b:  <\/p>\n<pre><code class=\"python\">...{ $group : {            _id : { a: &quot;$a&quot; },            user: { $push: &quot;$user&quot; },            blog: { $push: &quot;$blogs&quot; },         }  }...  {       &quot;_id&quot; : { &quot;a&quot; : null },       &quot;user&quot;: [               { &quot;_id&quot;: &quot;gomer&quot;, &quot;group&quot;: [ &quot;user&quot;, &quot;author&quot; ] },  { &quot;_id&quot;: &quot;vasya&quot;, &quot;group&quot;: [ &quot;user&quot; ] },                { &quot;_id&quot;: 1 }, { &quot;_id&quot;: 2 }, { &quot;_id&quot;: 3 }        ],       &quot;blog&quot;: [                { &quot;_id&quot;: &quot;gomer&quot; }, { &quot;_id&quot;: &quot;vasya&quot; }, { &quot;_id&quot;: 1, &quot;user&quot;: &quot;gomer&quot;, &quot;article&quot;: &quot;aaa&quot; },                {  &quot;_id&quot;: 2, &quot;user&quot;: &quot;vasya&quot;, &quot;article&quot;: &quot;bbb&quot; }, { &quot;_id&quot;: 3, &quot;user&quot;: &quot;gomer&quot;, &quot;article&quot;: &quot;ccc&quot;}          ]  } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 $unwind<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">....{ $unwind : &quot;$blog&quot; },     { $unwind : &quot;$user&quot; } ....  { &quot;_id&quot;: { &quot;a&quot;:null }, &quot;user&quot;: { &quot;_id&quot;: &quot;gomer&quot;, &quot;group&quot;: [ &quot;user&quot;, &quot;author&quot; ] }, &quot;blog&quot;: { &quot;_id&quot;: &quot;gomer&quot; } } { &quot;_id&quot;: { &quot;a&quot;:null }, &quot;user&quot;: { &quot;_id&quot;: &quot;vasya&quot;, &quot;group&quot;: [ &quot;user&quot; ] }, &quot;blog&quot; : { &quot;_id&quot;: &quot;gomer&quot; } } { &quot;_id&quot;: { &quot;a&quot;:null }, &quot;user&quot;: { &quot;_id&quot;: 1 }, &quot;blog&quot;: { &quot;_id&quot; : &quot;gomer&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 2 }, &quot;blog&quot; : { &quot;_id&quot; : &quot;gomer&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 3 }, &quot;blog&quot; : { &quot;_id&quot; : &quot;gomer&quot; } } { &quot;_id&quot;: { &quot;a&quot;: null }, &quot;user&quot;: { &quot;_id&quot;: &quot;gomer&quot;, &quot;group&quot; : [ &quot;user&quot;, &quot;author&quot; ] }, &quot;blog&quot;: { &quot;_id&quot;: &quot;vasya&quot;}} { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : &quot;vasya&quot;, &quot;group&quot; : [ &quot;user&quot; ] }, &quot;blog&quot; : { &quot;_id&quot; : &quot;vasya&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 1 }, &quot;blog&quot; : { &quot;_id&quot; : &quot;vasya&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 2 }, &quot;blog&quot; : { &quot;_id&quot; : &quot;vasya&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 3 }, &quot;blog&quot; : { &quot;_id&quot; : &quot;vasya&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : &quot;gomer&quot;, &quot;group&quot; : [ &quot;user&quot;, &quot;author&quot; ] }, &quot;blog&quot; : { &quot;_id&quot; : 1, &quot;user&quot;: &quot;gomer&quot;, &quot;article&quot; : &quot;aaa&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot;: { &quot;_id&quot;  &quot;vasya&quot;, &quot;group&quot;: [ &quot;user&quot; ] }, &quot;blog&quot;: { &quot;_id&quot;: 1, &quot;user&quot;: &quot;gomer&quot;, &quot;article&quot;: &quot;aaa&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 1 }, &quot;blog&quot; : { &quot;_id&quot; : 1, &quot;user&quot; : &quot;gomer&quot;, &quot;article&quot; : &quot;aaa&quot; } } { &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 2 }, &quot;blog&quot; : { &quot;_id&quot; : 1, &quot;user&quot; : &quot;gomer&quot;, &quot;article&quot; : &quot;aaa&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 3 }, &quot;blog&quot; : { &quot;_id&quot; : 1, &quot;user&quot; : &quot;gomer&quot;, &quot;article&quot; : &quot;aaa&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : &quot;gomer&quot;, &quot;group&quot; : [ &quot;user&quot;, &quot;author&quot; ] }, &quot;blog&quot; : { &quot;_id&quot; : 2, &quot;user&quot;: &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : &quot;vasya&quot;, &quot;group&quot; : [ &quot;user&quot; ] }, &quot;blog&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 1 }, &quot;blog&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 2 }, &quot;blog&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; } } { &quot;_id&quot;: { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 3 }, &quot;blog&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0415\u0449\u0435 \u0440\u0430\u0437 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0433\u0434\u0435 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <code>$eq:[ &quot;$user._id&quot;, &quot;$blog.user&quot; ]<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u043f\u043e\u043b\u0435\u0439 <code>&quot;user&quot; : { &quot;_id&quot; : 2 }<\/code> \u0438 <code>&quot;blog&quot; : { &quot;user&quot; : &quot;vasya&quot; } <\/code> \u0438 \u043c\u0430\u0440\u043a\u0438\u0440\u0443\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043d\u044b \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.  <\/p>\n<pre><code class=\"python\">...{ $project:{  \t\tuser:&quot;$user&quot;, \t\tarticle:&quot;$blog&quot;, \t\tmatches:{ $eq:[ &quot;$user._id&quot;, &quot;$blog.user&quot; ] } } } ..... <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">{ &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 1 }, &quot;article&quot; : { &quot;_id&quot; : 1, &quot;user&quot; : &quot;gomer&quot;, &quot;article&quot; : &quot;aaa&quot; }, &quot;matches&quot; : false } { &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 2 }, &quot;article&quot; : { &quot;_id&quot; : 1, &quot;user&quot; : &quot;gomer&quot;, &quot;article&quot; : &quot;aaa&quot; }, &quot;matches&quot; : false } { &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 3 }, &quot;article&quot; : { &quot;_id&quot; : 1, &quot;user&quot; : &quot;gomer&quot;, &quot;article&quot; : &quot;aaa&quot; }, &quot;matches&quot; : false } { &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : &quot;gomer&quot;, &quot;group&quot; : [ &quot;user&quot;, &quot;author&quot; ] }, &quot;article&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; }, &quot;matches&quot; : false } { &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : &quot;vasya&quot;, &quot;group&quot; : [ &quot;user&quot; ] }, &quot;article&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; }, &quot;matches&quot; : true } { &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 1 }, &quot;article&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; }, &quot;matches&quot; : false } { &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 2 }, &quot;article&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; }, &quot;matches&quot; : false } { &quot;_id&quot; : { &quot;a&quot; : null }, &quot;user&quot; : { &quot;_id&quot; : 3 }, &quot;article&quot; : { &quot;_id&quot; : 2, &quot;user&quot; : &quot;vasya&quot;, &quot;article&quot; : &quot;bbb&quot; }, &quot;matches&quot; : false } Type &quot;it&quot; for more <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c:  <\/p>\n<pre><code class=\"python\">{ $match: { matches:true } } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b><\/p>\n<div class=\"spoiler_text\">{ &quot;_id&quot;: { \u00aba\u00bb: null }, \u00abuser\u00bb: { &quot;_id&quot;: \u00abgomer\u00bb, \u00abgroup\u00bb: [ \u00abuser\u00bb, \u00abauthor\u00bb ] }, \u00abarticle\u00bb: { &quot;_id&quot;: 1, \u00abuser\u00bb: \u00abgomer\u00bb, \u00abarticle\u00bb: \u00abaaa\u00bb }, \u00abmatches\u00bb: true }<br \/>  { &quot;_id&quot;: { \u00aba\u00bb: null }, \u00abuser\u00bb: { &quot;_id&quot;: \u00abvasya\u00bb, \u00abgroup\u00bb: [ \u00abuser\u00bb ] }, \u00abarticle\u00bb: { &quot;_id&quot;: 2, \u00abuser\u00bb: \u00abvasya\u00bb, \u00abarticle\u00bb: \u00abbbb\u00bb }, \u00abmatches\u00bb: true }<br \/>  { &quot;_id&quot;: { \u00aba\u00bb: null }, \u00abuser\u00bb: { &quot;_id&quot;: \u00abgomer\u00bb, \u00abgroup\u00bb: [ \u00abuser\u00bb, \u00abauthor\u00bb ] }, \u00abarticle\u00bb: { &quot;_id&quot;: 3, \u00abuser\u00bb: \u00abgomer\u00bb, \u00abarticle\u00bb: \u00abccc\u00bb }, \u00abmatches\u00bb: true }  <\/div>\n<\/div>\n<p>  \u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e.<br \/>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u0430\u043a\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438 \u0432 \u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0435 \u043e\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442.<\/p>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0439 \u043d\u043e \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c <code>pipeline<\/code>.<\/p>\n<h3><a name=\"7\"><\/a> <font color=\"green\">7. \u041f\u0440\u0438\u043c\u0435\u0440\u044b <\/font><\/h3>\n<p>  \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0437\u0434\u0435\u0441\u044c \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442, \u0441\u043a\u043e\u0440\u0435\u0435, \u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0447\u0435\u043c \u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043e\u0431\u044b\u0447\u043d\u043e:   <\/p>\n<ul>\n<li>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445 \u043f\u043e\u0434\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u0435\u0439, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0438\u0441\u043a \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u0438\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430.<\/li>\n<li>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u0440\u0430\u044f\u0441\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0437\u0430\u043d\u043e\u0441\u0438\u0442\u044c \u0432 \u043d\u0438\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<h3><a name=\"71\"><\/a> <font color=\"blue\">\u0414\u0435\u0440\u0435\u0432\u044c\u044f, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438<\/font><\/h3>\n<p>  \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u042d\u0442\u043e \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u0438 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430\u0445, \u0438 \u0441\u0445\u0435\u043c\u044b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0430\u0445, \u0438 \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u0435\u0449\u0435. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/eda\/77e\/ded\/eda77eded16d42f783cf05019e2b81cc.png\"\/><\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0430\u0440\u0443 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<br \/>  \u0412 \u0432\u0438\u0434\u0435 \u0441\u0443\u0431\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432:  <\/p>\n<pre><code class=\"python\">{    _id:1, type:&quot;blog&quot;, title:{ru:&quot;O MongoDB&quot;, en:&quot;&quot;},      comments: [           { _id: 1, title: &quot;one&quot;, &quot;user&quot;: &quot;Alex&quot;, parent: &quot;root&quot;, child: [2, 3]},           { _id: 2, title: &quot;two&quot;, &quot;user&quot;: &quot;Serg&quot;, parent: 1 },                        { _id: 3, title: &quot;two&quot;, &quot;user&quot;: &quot;Andrey&quot;, parent: 1 }      ] } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b:  <\/p>\n<pre><code class=\"python\">{ _id: 1, type: &quot;comment&quot;, title: &quot;one&quot;, &quot;user&quot;: &quot;Alex&quot;, parent: &quot;root&quot;, child: [ 2, 3 ] }, { _id: 2, type: &quot;comment&quot;, title: &quot;two&quot;, &quot;user&quot;: &quot;Serg&quot;, parent: 1 },              { _id: 3, type: &quot;comment&quot;, title: &quot;two&quot;, &quot;user&quot;: &quot;Andrey&quot;, parent: 1 } <\/code><\/pre>\n<p>  \u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043e\u0431\u043e\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e.<br \/>  \u0422\u0435\u043c \u0431\u043e\u043b\u0435\u0435, \u0447\u0442\u043e \u043f\u043e \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b. <br \/>  \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u043f\u043e\u0434\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043d\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u0430\u043c\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043f\u043e\u0434\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445, \u0442\u0430\u043a\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043c\u043e\u0434\u043d\u044b\u043c \u043d\u044b\u043d\u0435 \u0441\u043b\u043e\u0432\u043e\u043c \u00ab\u0433\u0438\u0431\u0440\u0438\u0434\u043d\u0430\u044f\u00bb \u0441\u0445\u0435\u043c\u0430.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<br \/>  \u0423\u0434\u0430\u043b\u0438\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0442\u0435\u0439 \u0443 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f:  <\/p>\n<pre><code class=\"python\"> db.test.update( { _id: 1 }, { $pull: { child: 2 } } )  db.test.update( { _id: 1 }, { $pullAll: { child: [ 2, 3 ] } } ) <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0442\u0435\u0439 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044e:  <\/p>\n<pre><code class=\"python\"> db.test.update( { _id: 1 }, { $push: { child: 2 }  }  }  )  db.test.update( { _id: 1 }, { $push: { child: { $each: [ 2, 3 ] } } }  ) <\/code><\/pre>\n<p>  \u0421\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0438\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432:  <\/p>\n<pre><code class=\"python\">def getTree(docs): \ttree = { doc[&quot;_id&quot;]: doc for doc in docs } \tfor doc in docs: \t\tdoc['child'] = [] \tfor doc in docs: \t\tparent = doc[&quot;parent&quot;] \t\tif parent != &quot;root&quot;: \t\t\ttree[parent][&quot;child&quot;].append(doc) \tdocs={&quot;_id&quot;: &quot;root&quot;, &quot;child&quot;: [doc for doc in docs if doc['parent'] == &quot;root&quot; ]} \treturn docs   { _id: 1, type: &quot;comment&quot;, title: &quot;one&quot;, &quot;user&quot;: &quot;Alex&quot;,     parent: &quot;root&quot;,      child: [          { _id: 2, type: &quot;comment&quot;, title: &quot;two&quot;, &quot;user&quot;: &quot;Serg&quot;, parent: 1 },         { _id: 3, type: &quot;comment&quot;, title: &quot;two&quot;, &quot;user&quot;: &quot;Andrey&quot;, parent: 1 }     ]  } <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0434\u0435\u0440\u0435\u0432\u0430 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u0441\u0435\u0445 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439, \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0442\u043e\u0432\u0430\u0440\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f <code>_id<\/code> \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442:  <\/p>\n<pre><code class=\"python\">def count(cls): \tdb = connect() \tctr = db.test.find({'type':'goods', 'class':cls}).count() \tchilds = db.test.find_one({'_id':cls}) \tfor res in childs['child']: \t\tctr += count(res) \treturn ctr <\/code><\/pre>\n<p>  \u041d\u0430\u0439\u0434\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u043d\u0430\u0447\u0430\u043b\u0443, \u0437\u043d\u0430\u044f <code>_id<\/code> \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439:  <\/p>\n<pre><code class=\"python\">def path( id ):         p = [] \tparent = db.test.find_one( {&quot;_id&quot;: id }, { &quot;parent&quot;: 1, &quot;alias&quot;:1, &quot;title&quot;:1}) \telse: \t\tpath.append( ( parent['alias'], parent['title'] ) ) \t\tp += path( parent['parent'] ) \treturn p print ( path(&quot;123&quot;) )  &gt;&gt;&gt;[ (&quot;one&quot;, &quot;\u041f\u0435\u0440\u0432\u0430\u044f \u0432\u0435\u0442\u043a\u0430&quot;), (&quot;two&quot;, &quot;\u0412\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0442\u043a\u0430&quot;) ] <\/code><\/pre>\n<h3><a name=\"72\"><\/a> <font color=\"blue\">\u0422\u0435\u0433\u0438, \u0431\u043b\u043e\u0433\u0438<\/font><\/h3>\n<p>  \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0433\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0433\u0438\u0431\u0440\u0438\u0434\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u043f\u043e\u043b\u0435 <code>{ tags : { ru: &quot;\u043e\u0434\u0438\u043d, \u0434\u0432\u0430&quot; } }<\/code>, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u0441\u0440\u0430\u0437\u0443 \u0443\u0434\u043e\u0431\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u043c. \u0418 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u043d\u0438\u043c <code>{ tags : [ &quot;\u043e\u0434\u0438\u043d&quot;, &quot;\u0434\u0432\u0430&quot; ] }<\/code>.<br \/>  \u041e\u0431\u043b\u0430\u043a\u0430 \u0442\u0435\u0433\u043e\u0432 \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u043e\u0436\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0445\u0440\u0430\u043d\u044f\u0442, \u0438\u043d\u043e\u0433\u0434\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 \u043d\u0430 \u043b\u0435\u0442\u0443. <br \/>  \u041f\u043e\u0438\u0441\u043a \u043f\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0442\u0435\u0433\u043e\u0432, \u0435\u0441\u043b\u0438, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432:  <\/p>\n<pre><code class=\"python\"> { _id: 1, title: &quot;\u042f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f&quot;,  tags: [ &quot;php&quot;, &quot;python&quot; ]  }  db.test.find({ tags: { $in: [&quot;php&quot;, &quot;python&quot; ]  }  }  )  <\/code><\/pre>\n<p>  \u041d\u0443 \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c:  <\/p>\n<ul>\n<li>\u041f\u043e \u0442\u0435\u0433\u0430\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0445\u043e\u0442\u0438\u043c \u0447\u0442\u043e\u0431\u044b \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u0442\u0435\u0433\u0430\u043c\u0438 <code>python, javascript<\/code>.<\/li>\n<li>\u0418, \u0432 \u0442\u043e\u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0433\u0434\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0442\u0435\u0433\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u00ab\u0440\u0435\u043a\u043b\u0430\u043c\u0430\u00bb.<\/li>\n<li>\u041f\u043e \u0442\u0438\u043f\u0443, \u0443\u0447\u0442\u0435\u043c \u043a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0441\u0442\u0438.<\/li>\n<li>\u0423\u0447\u0442\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0437\u0430 \u0447\u044c\u0438\u043c \u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b.<\/li>\n<li>\u0422\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c.<\/li>\n<li>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u0440\u043e\u043a \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e\u0431 \u0432\u044b\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, 5 \u0434\u043d\u0435\u0439 \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438.<\/li>\n<li>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0439\u0442\u0438\u043d\u0433 \u043f\u043e\u043a\u0430\u0437\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0435\u0439\u0442\u0438\u043d\u0433 \u043c\u0435\u043d\u044c\u0448\u0435 <code>+2<\/code> \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c.<\/li>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0431\u044b\u043b\u0438 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u044b \u0438 \u043e\u0434\u043e\u0431\u0440\u0435\u043d\u044b \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u043c. <\/li>\n<li>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043b\u0438\u043c\u0438\u0442 \u0432 <code>10<\/code> \u0448\u0442\u0443\u043a \u0434\u043b\u044f \u043f\u043e\u043a\u0430\u0437\u0430. <\/li>\n<li>\u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430\u043c, \u0438 \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e (\u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u043e). <\/li>\n<\/ul>\n<pre><code class=\"python\">dt = ( datetime.today() + timedelta( days = -5 ) ) db.test.aggregate([     { $match: {         \/\/ \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0438\u043f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u0441\u0440\u043e\u043a \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438      \ttype: &quot;news&quot;, date: { $gt: dt },          \/\/  \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0439\u0442\u0438\u043d\u0433.         vate: { $gte: 2 },           \/\/\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u043a\u0430\u043a\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c.         user: { $in: [ &quot;alex&quot;, &quot;pavel&quot; ] }       \t$and: [               \/\/ \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d \u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u043e\u0434\u043e\u0431\u0440\u0435\u043d.              { pub: true }, { accept: true },               \/\/ \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e \u043a\u0430\u043a\u0438\u043c \u0442\u0435\u0433\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b.              { tags: { $in: [&quot;php&quot;, &quot;python&quot; ]  }  } ,               \/\/ \u0422\u0435\u0433\u0438 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0432\u0438\u0434\u0435\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b.              { tags: { $nin: [&quot;\u0440\u0435\u043a\u043b\u0430\u043c\u0430&quot;]  }  }      \t ]     },      \/\/ \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e \u0434\u0430\u0442\u0435.     { $sort: {'primary': -1, view: -1}},      \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043b\u0438\u043c\u0438\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 5      { $limit:3},     \/\/ \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 1 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e      \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.     { $group: {           '_id':'$user',          'id':    {'$first':'$_id'},          'type':{'$first':'$type'},          'title': {'$first':'$title'},          'content':{'$first':'$content'},          'count':{'$first':'$count_comm'},          'last_comm':{'$first':'$last_comm'},          'vote':{'$first':'$vote'},          'tags':{'$first':'$tags'}        }     },     \/\/  \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0432\u0438\u0434.     { $project :{         '_id':'$id', 'title':1,  'content':1, 'type':1,  'count':1,  'last_comm':1, 'tags':1, 'vote':1     }   } ]) <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0417\u0430\u043f\u0440\u043e\u0441 \u0431\u0435\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">db.test.aggregate([       { $match: {            type: &quot;news&quot;, date: { $gt: dt }, vate: { $gte: 2 }, user: { $in: [ &quot;alex&quot;, &quot;pavel&quot; ] }       \t   $and: [                  { pub: true }, { accept: true },                  { tags: { $in: [&quot;php&quot;, &quot;python&quot; ]  }  } ,                  { tags: { $nin: [&quot;\u0440\u0435\u043a\u043b\u0430\u043c\u0430&quot;]  }  }      \t   ]     },     { $sort: {'primary': -1, view: -1}},  { $limit:3},     { $group: {'_id':'$user',          'id':    {'$first':'$_id'},  'type':{'$first':'$type'},          'title': {'$first':'$title'},  'content':{'$first':'$content'},          'count':{'$first':'$count_comm'},          'last_comm':{'$first':'$last_comm'},          'vote':{'$first':'$vote'},  'tags':{'$first':'$tags'} \t}      },     { $project :{         '_id':'$id', 'title':1,  'content':1, 'type':1,  'count':1,  'last_comm':1, 'tags':1, 'vote':1     }   } ]) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u2014 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0438 \u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442.<\/p>\n<h3><a name=\"73\"><\/a> <font color=\"blue\">\u0415-commerce\u0438, \u0444\u0438\u043b\u044c\u0442\u0440\u044b<\/font><\/h3>\n<p>  \u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0437\u0430\u0434\u0430\u0447 \u0432\u0435\u0431-\u043c\u0430\u0433\u0430\u0437\u0438\u043d\u043e\u0432 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0443\u0447\u0451\u0442\u043e\u0432 \u2014 \u044d\u0442\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u044b. \u041e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u043a\u0430\u043a \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0445\u0438\u0442\u0440\u044b\u0445 \u043e\u0442\u0447\u0435\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430 \u0433\u0434\u0435 \u0447\u0442\u043e \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435, \u043d\u0443 \u0438, \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e, \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0438 \u043f\u043e \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438, \u0446\u0435\u043d\u0435, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044e \u0438 \u043f\u0440\u043e\u0447\u0435\u043c\u0443. <\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c, \u0438\u0437-\u0437\u0430 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430, \u043c\u044b \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f\u0445.<\/p>\n<p>  \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u0432\u0438\u0434\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432, \u0438\u043b\u0438, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435, \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0432 \u0432\u0435\u0431-\u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435.   <\/p>\n<ol>\n<li>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u043d\u0438\u0447\u0435\u0433\u043e (\u0447\u0430\u0441\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043f\u0440\u0430\u0439\u0441 \u0438\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u0441 \u043a\u0430\u043a\u043e\u0433\u043e \u0442\u043e \u0441\u0430\u0439\u0442\u0430 )<\/li>\n<li>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c.<\/li>\n<\/ol>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u044f, \u043d\u0438 \u0441 \u0447\u0435\u043c \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435, \u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e \u043d\u0438\u043c \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u2014 \u0438 \u0432\u0441\u0451. \u041d\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0438 \u0443\u0447\u0435\u0442\u0430, \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043d\u043e\u0441\u0438\u0442\u044c.<\/p>\n<p>  \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \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 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u044b \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0442\u0435\u043c \u0438\u043b\u0438 \u0438\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043a \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u043c \u0442\u043e\u0432\u0430\u0440\u043e\u0432 (\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c).<\/p>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u044d\u0442\u0430\u043f\u043e\u0432:  <\/p>\n<ol>\n<li>\u041f\u043e\u043a\u0430\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0443 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u0435\u0441\u0442\u044c \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c \u0430 \u0443 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u0442\u0430\u043a\u0442\u043e\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u0430.<\/li>\n<li>\u0418 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u044d\u0442\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c.<\/li>\n<\/ol>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u043e\u043a\u0430\u0437\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u043a \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u043c \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u0442\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0418 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c:  <\/p>\n<pre><code class=\"python\">cursor = db.test.find({ &quot;type&quot;: &quot;filters&quot;, &quot;category&quot;: &quot;id_category&quot; }) <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e \u0440\u0430\u0437\u043d\u043e\u043c\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u0433\u0434\u0435 \u043f\u0435\u0440\u0432\u044b\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432, \u0430 \u0432\u0442\u043e\u0440\u044b\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0435\u0433\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438.<br \/>  \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 =&gt; \u0414\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c<br \/>  \u0425\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438=&gt; 15.6 \u0434\u044e\u0439\u043c\u0430, 17 \u0434\u044e\u0439\u043c\u043e\u0432 \u0438 \u0442\u0434.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/343\/713\/af0\/343713af0a4e47588b02aee8bb545469.png\"\/><\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043f\u043e\u0439\u0442\u0438 \u043a\u0430\u043a \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c \u043f\u0443\u0442\u0435\u043c. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u043f\u043e \u0442\u0438\u043f\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u043d\u044b\u0445 \u0438 \u0440\u0430\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0445. \u041a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0448\u0430\u043f\u043a\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0440\u0435\u043a\u0432\u0438\u0437\u0438\u0442\u043e\u0432 \u0438 \u0442\u0434., \u0438 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0441\u043d\u0438\u0437\u0443. <br \/>  \u0422\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0448\u0430\u043f\u043a\u0430 \u2014 \u044d\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u044b, \u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u2014 \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/6af\/70b\/37a\/6af70b37a5ce41af9d27ec59a164aa16.png\"\/><\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. \u042d\u0442\u043e \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0438\u0437 \u0441\u0430\u043c\u0438\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043e\u043f\u0438\u0448\u0435\u043c.<\/p>\n<p>  \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0445\u0441\u044f \u0438\u043b\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445, \u0438\u043b\u0438 \u0432 \u043d\u0435\u043c \u0441\u0430\u043c\u043e\u043c \u0432 \u0441\u0443\u0431\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445. \u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/bec\/a7b\/61f\/beca7b61f10d423386fda03f5b966e02.png\"\/><\/p>\n<p>  \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b. \u0416\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0442\u043e\u0431\u044b _id \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u043e\u0441\u044c \u0442\u043e\u0433\u0434\u0430 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u0441 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u043e\u0439.<br \/>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>$addToSet<\/code> \u043f\u0440\u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.  <\/p>\n<pre><code class=\"python\">db.test.aggregate([      \/\/ \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0442\u0438\u043f\u0443 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0430 \u0438 \u043f\u043e id \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438                  { '$match': { type : &quot;goods_attr&quot;,  category: id_category } },      \/\/ \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438, \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044f \u043b\u0438\u0448\u043d\u0438\u0435 \u043f\u043e\u043b\u044f       { '$project': { &quot;title&quot; : &quot;$title.ru&quot;, 'value': &quot;$attr.ru&quot;, 'category': &quot;$category&quot;, '_id': 0 } },      { '$group' : {             '_id': { 'category' :&quot;$category&quot;, 'title': &quot;$title&quot;} ,              'filters': { '$addToSet': &quot;$value&quot; }           }       },      { '$group' : {           '_id' :&quot;$_id.category&quot;, 'title':{ '$addToSet': { 'title': &quot;$_id.title&quot;, 'filters': &quot;$filters&quot; } }           }       } ]) <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e group \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430:  <\/p>\n<pre><code class=\"python\">...{ '$group'   : {          '_id': { 'category' :&quot;$category&quot;, 'title': &quot;$title&quot;} ,           'filters': { '$addToSet': &quot;$value&quot; }       }  }....  { &quot;_id&quot;: { &quot;category&quot;: &quot;id&quot;, &quot;title&quot;: &quot;\u0423\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u043a \u0430\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u044b\u043c \u0441\u0440\u0435\u0434\u0430\u043c&quot; }, &quot;filters&quot;: [ &quot;\u0414\u0430&quot; ] } { &quot;_id&quot; : { &quot;category&quot; : &quot;id&quot;, &quot;title&quot; : &quot;\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b&quot; }, &quot;filters&quot; : [ &quot;\u041d\u0435\u0440\u0436\u0430\u0432\u0435\u044e\u0449\u0430\u044f \u0441\u0442\u0430\u043b\u044c&quot; ] } { &quot;_id&quot; : { &quot;category&quot; : &quot;id&quot;, &quot;title&quot; : &quot;\u0422\u0438\u043f \u0437\u0430\u0436\u0438\u043c\u0430&quot; }, &quot;filters&quot; : [ &quot;\u041d\u0430\u0442\u044f\u0436\u043d\u043e\u0439&quot; ] } <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e group \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.  <\/p>\n<pre><code class=\"python\">...{ '$group'   : {          '_id':&quot;$_id.category&quot;, 'title':{'$addToSet': {'title': &quot;$_id.title&quot;, 'filters': &quot;$filters&quot; }}        }  ...}  {       &quot;_id&quot; : &quot;id_category&quot;,        &quot;title&quot; : [               { &quot;title&quot; : &quot;\u0422\u0438\u043f \u0430\u0440\u043c\u0430\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u041b\u042d\u041f&quot;, &quot;filters&quot; :                      [ &quot;\u041a\u0440\u044e\u043a \u0434\u043b\u044f \u041b\u042d\u041f&quot;, &quot;\u0421\u043a\u0440\u0435\u043f\u0430 \u0434\u043b\u044f \u041b\u042d\u041f&quot;, &quot;\u041b\u0435\u043d\u0442\u0430 \u0431\u0430\u043d\u0434\u0430\u0436\u043d\u0430\u044f&quot;, &quot;\u0417\u0430\u0436\u0438\u043c \u0434\u043b\u044f \u041b\u042d\u041f&quot; ]                },                { &quot;title&quot; : &quot;\u0422\u0438\u043f \u0437\u0430\u0436\u0438\u043c\u0430&quot;, &quot;filters&quot; : [ &quot;\u041d\u0430\u0442\u044f\u0436\u043d\u043e\u0439&quot; ] },                { &quot;title&quot; : &quot;\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b&quot;, &quot;filters&quot; : [ &quot;\u041d\u0435\u0440\u0436\u0430\u0432\u0435\u044e\u0449\u0430\u044f \u0441\u0442\u0430\u043b\u044c&quot; ] },                { &quot;title&quot; : &quot;\u0423\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u043a \u0430\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u044b\u043c \u0441\u0440\u0435\u0434\u0430\u043c&quot;, &quot;filters&quot; : [ &quot;\u0414\u0430&quot; ] }         ]  }  <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e \u044d\u0442\u0438\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0438\u0449\u0435\u043c \u043f\u043e \u0441\u0443\u0431\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u043c, \u0442\u043e \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e <code>owner_id<\/code> \u044d\u0442\u043e _id \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438.<\/p>\n<pre><code class=\"python\">db.test.aggregate([      { '$match'  :           { 'type' : &quot;goods_attr&quot;, &quot;category'':&quot;id&quot;,                '$or': [                    {'title': '\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b', 'attr': '\u041d\u0435\u0440\u0436\u0430\u0432\u0435\u044e\u0449\u0430\u044f \u0441\u0442\u0430\u043b\u044c'},                     {'title': '\u0422\u0438\u043f \u0430\u0440\u043c\u0430\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u041b\u042d\u041f', 'attr_val': '\u041a\u0440\u044e\u043a \u0434\u043b\u044f \u041b\u042d\u041f'}                ]             }       },      { '$group': {'_id': &quot;$owner_id&quot;, &quot;attr&quot;: { '$push': &quot;$title&quot; }}},      { '$match': {&quot;attr&quot;: {'$all': [ '\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b',  '\u0422\u0438\u043f \u0430\u0440\u043c\u0430\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u041b\u042d\u041f' ] }}},      { '$project': {&quot;_id&quot;:1 } } ]) <\/code><\/pre>\n<p>  \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a _id \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u043e\u0434 \u0444\u0438\u043b\u044c\u0442\u0440\u044b.<\/p>\n<h3><a name=\"8\"><\/a> <font color=\"green\">\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430 \u0434\u043b\u044f Python<\/font><\/h3>\n<p>  \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u0434\u043e\u0431\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a. <\/p>\n<p>  \u041d\u043e \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043f\u043e\u043b\u044f \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 (\u0447\u0438\u0442\u0430\u0439 \u2014 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435) \u043a\u0430\u043a\u043e\u0435 \u043b\u0438\u0431\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 \u0432 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0435 \u0432\u0430\u043b\u044e\u0442 \u043a\u0443\u0440\u0441 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0437\u0430\u043a\u0443\u043f\u0430\u0435\u043c, \u0438 \u0445\u043e\u0442\u0438\u043c \u0447\u0442\u043e\u0431 \u0446\u0435\u043d\u044b \u0432 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u0435 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u0430\u043b\u0438\u0441\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432. <\/p>\n<p>  \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 ERP \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u0418, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0447\u0430\u0441\u0442\u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043a\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b \u043a\u043e\u0434, \u043d\u0443\u0436\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u044e\u0442 \u044d\u0442\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u0442\u043e\u0447\u043d\u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043a\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e \u043e\u043d\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<p>  \u0415\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043a\u043e\u0434 \u0432 <code>python<\/code>, \u043e\u043d \u043f\u0440\u0438\u0432\u043d\u043e\u0441\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u0447 \u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 <code>exec<\/code>  <\/p>\n<pre><code class=\"python\">src = ''' result = 0 for i in xrange(100):     result += i '''  assert '__' not in src, 'Prohibited to use symbols &quot;__&quot;' pr = compile(src, '&lt;string&gt;', mode='exec') glob = { '__builtins__':{ 'xrange':xrange } } exec(pr, glob) print glob['result'] <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 <code>eval<\/code> (\u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f)  <\/p>\n<pre><code class=\"python\">src = 'max(5,7,3)' glob = { '__builtins__':{ 'max':max } } assert '__' not in src, 'Prohibited to use symbols &quot;__&quot;' print ( eval(src, glob) ) <\/code><\/pre>\n<p>  \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u044d\u0442\u043e:<br \/>  <code>assert '__' not in src, 'Prohibited to use symbols &quot;__&quot;'<\/code><br \/>   \u2014 \u0437\u0430\u043f\u0440\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u043f\u0435\u0446 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c, \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0438:<code> __class__, __base__<\/code><br \/>  \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a python \u0438  <\/p>\n<pre><code class=\"python\">glob = { '__builtins__':{ 'xrange':xrange } } <\/code><\/pre>\n<p>  \u0442\u0443\u0442 \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u0435\u0441\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b (import, type&#8230;) \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439\/\u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>getattr<\/code>.<\/p>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u043d\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c <code>sandbox<\/code>.<\/p>\n<p>  P.S. \u041f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0442\u044c, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0443\u043d\u043a\u0442\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e. \u041f\u0440\u043e\u0441\u044c\u0431\u0430 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0430 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043b\u0438\u0447\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0434\u043b\u0438\u043d\u043d\u0430\u044f, \u043c\u043e\u0433 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c. <\/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\/manual\/\">\u0421\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u043e mongodb <\/a><br \/>  <a href=\"http:\/\/docs.mongodb.org\/manual\/reference\/operator\/\">\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <\/a><br \/>  <a href=\"http:\/\/docs.mongodb.org\/manual\/administration\/indexes-text\/\">\u0412\u0441\u0435 \u043f\u0440\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a<\/a><br \/>  <a href=\"http:\/\/docs.mongodb.org\/getting-started\/python\/client\/\"> \u0421\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u043e PyMongo <\/a><br \/>  <a href=\"http:\/\/docs.mongodb.org\/manual\/release-notes\/2.6-upgrade\/\">\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 mongodb \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 2.6 <\/a><br \/>  <a href=\"http:\/\/docs.mongodb.org\/manual\/release-notes\/3.0-upgrade\/\">\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 mongodb \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 3.0 <\/a><br \/>  <a href=\"http:\/\/docs.mongodb.org\/manual\/reference\/sql-aggregation-comparison\/\">\u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 aggregation pipeline <\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/139643\/\">\u0421\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u043f\u0440\u043e aggregation pipeline <\/a><br \/>  <a href=\"http:\/\/docs.mongodb.org\/manual\/core\/write-operations-atomicity\/\">\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445<\/a><\/p>\n<\/h5>\n<\/h5>\n<\/h5>\n<\/h5>\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\/259219\/\"> http:\/\/habrahabr.ru\/post\/259219\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/e36\/58a\/ca6\/e3658aca69ab496895f5bc53c7357632.jpeg\"\/><\/p>\n<p>  \u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u2014 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e <code>mongodb<\/code> \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043f\u0430\u0440\u043e\u0439 \u0440\u0435\u0446\u0435\u043f\u0442\u043e\u0432. \u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043c\u0435\u043b\u043e\u0447\u0438 \u0441\u043e\u0431\u0440\u0430\u043d\u044b \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f <code>mongodb<\/code> \u043d\u0430\u0439\u0434\u0435\u0442 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435.<\/p>\n<p>  \u041d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0442 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u0441\u044f \u0432 \u043a\u043b\u044e\u0447\u0435 \u0445\u043e\u043b\u0438\u0432\u0430\u0440\u043e\u0432 \u043d\u0430 \u0442\u0435\u043c\u0443 <code>SQL vs. NOSQL<\/code> \u0418 \u0442\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0447\u0442\u043e \u0432\u0435\u0437\u0434\u0435 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043f\u0440\u0430\u0432\u043a\u0438, \u0433\u0434\u0435-\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0437 \u0442\u043e\u0433\u043e, \u0441 \u0447\u0435\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0430 <code>mongo shell<\/code> \u0438\u043b\u0438 \u043d\u0430 <code>python<\/code>.<\/p>\n<ol>\n<li><a href=\"#1\">\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0432 \u043d\u0430 \u043d\u043e\u0432\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0432 mongodb<\/a><br \/> \n<ul>\n<li><a href=\"#11\"> \u0414\u043e \u0432\u0435\u0440\u0441\u0438\u0438 2.6 <\/a><\/li>\n<li><a href=\"#12\"> \u0421 2.6 \u0434\u043e 3.0 \u0432\u0435\u0440\u0441\u0438\u0438 <\/a><\/li>\n<li><a href=\"#13\"> \u041d\u043e\u0432\u043e\u0435 \u0432 PyMongo <\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#2\"> \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435<\/a><\/li>\n<li><a href=\"#3\"> \u041f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a, regexp, \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0438 \u043f\u0440.<\/a><\/li>\n<li><a href=\"#4\"> \u0410\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b (\u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 )<\/a><\/li>\n<li><a href=\"#5\"> \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u0445 \u0432 Mongodb<\/a><br \/> \n<ul>\n<li><a href=\"#51\"> \u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 <\/a><\/li>\n<li><a href=\"#52\"> \u0414\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u043c\u043c\u0438\u0442 <\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#6\"> \u0410\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438 JOIN-\u044b<\/a><\/li>\n<li><a href=\"#7\"> \u041f\u0440\u0438\u043c\u0435\u0440\u044b <\/a><br \/> \n<ul>\n<li><a href=\"#71\"> \u0414\u0435\u0440\u0435\u0432\u044c\u044f, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438<\/a><\/li>\n<li><a href=\"#72\"> \u0422\u0435\u0433\u0438, \u0431\u043b\u043e\u0433\u0438 <\/a><\/li>\n<li><a href=\"#73\"> \u0415-commerce, \u0444\u0438\u043b\u044c\u0442\u0440\u044b <\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#8\"> \u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430 \u043d\u0430 Python<\/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-258435","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/258435","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=258435"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/258435\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=258435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=258435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=258435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}