{"id":3479,"date":"2018-12-04T17:37:53","date_gmt":"2018-12-04T09:37:53","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3479"},"modified":"2018-12-04T17:37:53","modified_gmt":"2018-12-04T09:37:53","slug":"%e8%af%a6%e8%a7%a3-com-mongodb-client-model-updates-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3479","title":{"rendered":"\u8be6\u89e3 com.mongodb.client.model.Updates \u6559\u7a0b"},"content":{"rendered":"<p>\n\t\u7f51\u4e0a\u641c\u7d22\u4e86\u4e00\u4e0b\u5173\u4e8e MongoDB \u7684\u76f8\u5173\u6559\u7a0b\uff0c\u53d1\u73b0\u975e\u5e38\u7684\u5c11\uff0c\u5c11\u7684\u53ef\u601c\u3002\u7f51\u4e0a\u7684\u591a\u5c11\u6559\u7a0b\u90fd\u662f\u57fa\u4e8e\u67e5\u8be2 SQL \u7684\uff0c\u5f88\u5c11\u6709\u57fa\u4e8e Java Api \u6765\u5199\u7684\u3002\u56e0\u6b64\uff0c\u6211\u6700\u8fd1\u4e00\u76f4\u5728\u770b MongoDB \u7684\u76f8\u5173\u9a71\u52a8\u5305\u7684\u6e90\u7801\uff0c\u8bd5\u7740\u7ed9\u5927\u5bb6\u5206\u4eab\u4e00\u4e9b\u5173\u4e8e MongoDB \u7684\u76f8\u5173\u6559\u7a0b\u548c\u7528\u6cd5\u3002\n<\/p>\n<p>\n\tUpdates \u7c7b\u4e5f\u662f\u4e00\u4e2a final \u7c7b\uff0c\u5b83\u867d\u7136\u5728 com.mongodb.client.model \u5305\u91cc\u9762\uff0c\u4f46\u5b83\u7684\u4f5c\u7528\u5374\u975e\u5e38\u7684\u5f3a\u5927\u3002Updates \u91cc\u9762\u7684\u65b9\u6cd5\u90fd\u662f\u9759\u6001\u65b9\u6cd5\uff0c\u9759\u6001\u65b9\u6cd5\u662f MongoDB java \u9a71\u52a8\u5305\u7684\u4e00\u5927\u7279\u8272\u3002Updates \u7c7b\u7684\u6784\u9020\u51fd\u6570\u88ab\u79c1\u6709\u5316\u4e86\uff0c\u6240\u4ee5\u91cc\u9762\u90fd\u662f\u9759\u6001\u65b9\u6cd5\u3002\n<\/p>\n<p>\n\tUpdates \u7c7b\u88ab\u5b98\u65b9\u79f0\u4e3a\u66f4\u65b0\u5de5\u5382\u3002\u5b83\u91cc\u9762\u8fd8\u63d0\u4f9b\u4e86 5 \u4e2a\u5185\u90e8\u7c7b\u3002CompositeUpdate \u7c7b\u662f\u6bd4\u8f83\u5e38\u7528\u7684\uff0c\u5b83\u7ecf\u5e38\u88ab\u7528\u6765\u7ec4\u5408\u67e5\u8be2\u6761\u4ef6\u6216\u8005\u662f\u7ec4\u5408\u66f4\u65b0\u7684 set \u503c\u7684\u96c6\u5408\u3002\u5e38\u89c1\u7684\u7528\u6cd5\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\nupdateMany(and(eq(&quot;url&quot;, &quot;www.xttblog.com&quot;), eq(&quot;hidden&quot;, true), eq(&quot;type&quot;, &quot;admin&quot;)),\r\n combine(set(&quot;name&quot;, &quot;\u4e1a\u4f59\u8349&quot;), set(&quot;createTime&quot;, System.currentTimeMillis() \/ 1000)));<\/pre>\n<p>\n\t\u7b2c\u4e8c\u4e2a\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u5c31\u662f Updates.set \u65b9\u6cd5\uff0c\u5b83\u76f8\u5f53\u4e8e $set \u7684\u7528\u6cd5\uff0c\u6211\u5c31\u4e0d\u8fc7\u591a\u89e3\u91ca\u3002\u7528\u6cd5\u5c31\u548c\u4e0a\u9762\u7684\u4f8b\u5b50\u4e00\u6837\uff0c\u76f4\u63a5\u8c03\u7528 set \u65b9\u6cd5\u5373\u53ef\uff0c\u4ee3\u8868 set \u7684\u5b57\u6bb5\u9700\u8981\u66f4\u65b0\u65b0\u503c\u3002\n<\/p>\n<p>\n\t\u5269\u4e0b\u7684\u4e00\u4e9b\u7528\u6cd5\uff0c\u6211\u5c31\u5927\u81f4\u7684\u8bb2\u89e3\u4e00\u4e0b\uff0cunset \u76f8\u5f53\u4e8e\u5220\u9664\u3002\n<\/p>\n<p>\n\tsetOnInsert \u65b9\u6cd5\u7684\u7528\u6cd5\uff0c\u76f8\u5f53\u4e8e $setOnInsert\uff0c\u4ee3\u8868\uff1a\u5982\u679c\u66f4\u65b0\u7684\u503c\u5b58\u5728\uff0c\u5219\u4e0d\u505a\u64cd\u4f5c\uff1b\u5982\u679c\u66f4\u65b0\u7684\u503c\u4e0d\u5b58\u5728\u5219\u63d2\u5165\u65b0\u7684\u5b57\u6bb5\u3002\n<\/p>\n<p>\n\trename \u65b9\u6cd5\u76f8\u5f53\u4e8e $rename \u7684\u7528\u6cd5\uff0c\u91cd\u547d\u540d\u5df2\u7ecf\u5b58\u5728\u7684\u5b57\u6bb5\u3002\u66f4\u65b0\u540e\u7684\u5b57\u6bb5\u540d\u4e0d\u80fd\u548c\u539f\u5b57\u6bb5\u540d\u76f8\u540c\u3002\n<\/p>\n<p>\n\tinc \u65b9\u6cd5\u76f8\u5f53\u4e8e $inc \u7684\u7528\u6cd5\u3002\u5b83\u7528\u6765\u5728\u539f\u503c\u4e0a\u589e\u52a0\u5185\u5bb9\uff0c\u6bd4\u5982\u6211\u73b0\u5728\u7684\u5e93\u5b58\u662f 50\uff0c\u6211\u53c8\u8fdb\u4e86\u4e00\u6279\u8d27\uff0c\u9700\u8981\u5728\u539f\u503c\u4e0a\u589e\u52a0 20\uff0c\u600e\u4e48\u529e\uff1f\u7528 inc \u65b9\u6cd5\u5373\u53ef\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\nupdateMany(eq(&quot;sku&quot;, &quot;501111&quot;), inc(&quot;quantity&quot;, 50));<\/pre>\n<p>\n\tmul \u65b9\u6cd5\u76f8\u5f53\u4e8e $mul\uff0c$mul \u64cd\u4f5c\u7b26\u7528\u4e00\u4e2a\u6570\u5b57\u4e58\u4ee5\u4e00\u4e2a\u503c\u3002\u6bd4\u5982 $mul: { price : 1.25 } \u8868\u793a\uff0cprice \u7684\u503c\u5728\u539f\u6765\u7684\u57fa\u7840\u4e0a\u4e58\u4ee5 1.25\u3002\n<\/p>\n<p>\n\tmin \u65b9\u6cd5\u76f8\u5f53\u4e8e $min\uff0c\u5c31\u662f\u4ee3\u8868\u6700\u5c0f\u503c\u3002\n<\/p>\n<p>\n\tmax \u65b9\u6cd5\u76f8\u5f53\u4e8e $max \u64cd\u4f5c\uff0c\u4ee3\u8868\u6700\u5927\u503c\u3002\n<\/p>\n<p>\n\tcurrentDate \u65b9\u6cd5\u76f8\u5f53\u4e8e $currentDate \u64cd\u4f5c\u3002\u8bbe\u7f6e\u65f6\u95f4\u4e3a\u5f53\u524d\u65f6\u95f4\u3002\n<\/p>\n<p>\n\tcurrentTimestamp \u65b9\u6cd5\uff0c\u76f8\u5f53\u4e8e\u5229\u7528 $currentDate \u8bbe\u7f6e\u65f6\u95f4\u4e3a\u5f53\u524d\u65f6\u95f4\uff0c\u5e76\u4e14\u65f6\u95f4\u7c7b\u578b\u4e3a timestamp \u7c7b\u578b\u3002\n<\/p>\n<p>\n\taddToSet \u65b9\u6cd5\u76f8\u5f53\u4e8e $addToSet \u64cd\u4f5c\u3002$addToSet \u6dfb\u52a0\u503c\u5230\u4e00\u4e2a\u6570\u7ec4\u4e2d\u53bb\uff0c\u5982\u679c\u6570\u7ec4\u4e2d\u5df2\u7ecf\u5b58\u5728\u8be5\u503c\u90a3\u4e48\u5c06\u4e0d\u4f1a\u6709\u4efb\u4f55\u7684\u64cd\u4f5c\u3002\n<\/p>\n<p>\n\taddEachToSet \u65b9\u6cd5\u5c31\u76f8\u5f53\u4e8e $addToSet \u64cd\u4f5c\u7b26\u548c $each \u4fee\u9970\u7b26\u914d\u5408\u4f7f\u7528\u3002$each \u4fee\u9970\u7b26\u5141\u8bb8 $addToSet \u64cd\u4f5c\u7b26\u6dfb\u52a0\u591a\u4e2a\u5143\u7d20\u5230\u6570\u7ec4\u5b57\u6bb5\u4e2d\u3002\n<\/p>\n<p>\n\tpush \u65b9\u6cd5\u76f8\u5f53\u4e8e $push \u64cd\u4f5c\u3002$push \u64cd\u4f5c\u7b26\u6dfb\u52a0\u6307\u5b9a\u7684\u503c\u5230\u6570\u7ec4\u4e2d\u3002\n<\/p>\n<p>\n\tpushEach \u65b9\u6cd5\u76f8\u5f53\u4e8e\u4f7f\u7528 $push \u64cd\u4f5c\u7b26\u548c $each \u4fee\u9970\u7b26\u4e00\u8d77\u6dfb\u52a0\u591a\u4e2a\u503c\u5230\u6570\u7ec4\u5b57\u6bb5\u4e2d\u3002\n<\/p>\n<p>\n\tpull \u65b9\u6cd5\u76f8\u5f53\u4e8e $pull \u64cd\u4f5c\uff0c$pull \u4fee\u9970\u7b26\u4f1a\u5220\u9664\u6389\u6570\u7ec4\u4e2d\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\u3002\n<\/p>\n<p>\n\tpullByFilter \u65b9\u6cd5\u987e\u540d\u601d\u4e49\u5c31\u662f\u6839\u636e\u8fc7\u6ee4\u7684\u6761\u4ef6\u5220\u9664\u6389\u6570\u7ec4\u4e2d\u7684\u6307\u5b9a\u5143\u7d20\u3002\n<\/p>\n<p>\n\tpullAll \u65b9\u6cd5\u5c31\u662f\u5220\u9664\u6389\u6570\u7ec4\u5185\u7684\u591a\u4e2a\u5185\u5bb9\u3002\u5185\u90e8\u662f\u9760 PullAllUpdate \u7c7b\u5b9e\u73b0\u7684\u3002\u7528\u6cd5\u76f8\u5f53\u4e8e $pull\uff0c\u53ea\u4e0d\u8fc7\u53ef\u4ee5\u4e00\u6b21\u5220\u9664\u591a\u4e2a\u503c\u3002\n<\/p>\n<p>\n\tpopFirst \u65b9\u6cd5\u5c31\u76f8\u5f53\u4e8e $pop \u64cd\u4f5c\u3002$pop \u4fee\u9970\u7b26\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u7b2c\u4e00\u4e2a\u6216\u8005\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u7ed9 $pop \u4f20\u9012 -1 \u4f1a\u5220\u9664\u7b2c\u4e00\u4e2a\u5143\u7d20\u4f20\u9012 1 \u4f1a\u5220\u9664\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002popFirst \u65b9\u6cd5\u5185\u90e8\u662f\u9760 SimpleUpdate \u7c7b\u5b9e\u73b0\u7684\uff0c\u5176\u5b9e\u5c31\u662f $pop \u64cd\u4f5c\u4f20\u9012\u4e86 -1\u3002\n<\/p>\n<p>\n\tpopLast \u8fd9\u4e2a\u65b9\u6cd5\u548c popFirst \u90fd\u5dee\u4e0d\u591a\uff0c\u4e00\u4e2a\u662f $pop \u4f20\u9012 -1\uff0c\u4e00\u4e2a\u662f $pop \u4f20\u9012 1\u3002\n<\/p>\n<p>\n\tbitwiseAnd \u65b9\u6cd5\u5185\u90e8\u662f $bit \u64cd\u4f5c\u3002$bit \u652f\u6301\u6309\u4f4d\u66f4\u65b0\u3002\u8fd0\u7b97\u7b26\u652f\u6301\u6309\u4f4d and\uff0c\u6309\u4f4d or \u548c\u6309\u4f4d xor\uff08\u5373\u5f02\u6216\uff09\u8fd0\u7b97\u3002\n<\/p>\n<p>\n\tbitwiseOr \u548c bitwiseXor \u90fd\u548c bitwiseAnd \u65b9\u6cd5\u7c7b\u4f3c\uff0c\u6211\u5c31\u4e0d\u5728\u591a\u8bf4\u4e86\u3002\u603b\u800c\u8a00\u4e4b\uff0c\u770b\u4e00\u7bc7\u4e0d\u5982\u81ea\u5df1\u64cd\u4f5c\u4e00\u7bc7\uff0c\u53ea\u6709\u81ea\u5df1\u64cd\u4f5c\u4e00\u904d\u624d\u6709\u611f\u89c9\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3479\">\u8be6\u89e3 com.mongodb.client.model.Updates \u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u7f51\u4e0a\u641c\u7d22\u4e86\u4e00\u4e0b\u5173\u4e8e MongoDB \u7684\u76f8\u5173\u6559\u7a0b\uff0c\u53d1\u73b0\u975e\u5e38\u7684\u5c11\uff0c\u5c11\u7684\u53ef\u601c\u3002\u7f51\u4e0a\u7684\u591a\u5c11\u6559\u7a0b\u90fd\u662f\u57fa\u4e8e\u67e5\u8be2 SQL \u7684 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1578,1577,747,394,430],"class_list":["post-3479","post","type-post","status-publish","format-standard","hentry","category-java","tag-mongodb","tag-nosql","tag-747","tag-394","tag-430"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3479"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3479\/revisions"}],"predecessor-version":[{"id":3480,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3479\/revisions\/3480"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}