{"id":206990,"date":"2025-07-08T08:19:49","date_gmt":"2025-07-08T00:19:49","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206990\/"},"modified":"2025-07-08T08:19:49","modified_gmt":"2025-07-08T00:19:49","slug":"firestore-%e6%89%b9%e5%a4%84%e7%90%86-%e9%9c%80%e8%a6%81%e8%b6%85%e8%bf%87-1-%e6%ac%a1%e5%86%99%e5%85%a5%e7%9a%84%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206990\/","title":{"rendered":"Firestore \u6279\u5904\u7406 &#8211; \u9700\u8981\u8d85\u8fc7 1 \u6b21\u5199\u5165\u7684\u64cd\u4f5c"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>Firestore \u6279\u5904\u7406 &#8211; \u9700\u8981\u8d85\u8fc7 1 \u6b21\u5199\u5165\u7684\u64cd\u4f5c<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 12:12:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aFirestore \u6279\u5904\u7406 &#8211; \u9700\u8981\u8d85\u8fc7 1 \u6b21\u5199\u5165\u7684\u64cd\u4f5c\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p><em>tl;dr<\/em> &#8211; \u90a3\u91cc\u6709\u4e00\u4e9b\u7ea6\u5b9a\/\u6709\u6548\u8d1f\u8f7d\/\u64cd\u4f5c\uff0c\u8fd9\u9700\u8981\u8fdb\u884c\u8d85\u8fc7 1 \u6b21\u6279\u91cf\u5199\u5165\u3002<\/p>\n<p>\u6211\u53d1\u73b0\uff0c\u5f53\u6211\u5c06 <code>set<\/code> \u64cd\u4f5c\u6dfb\u52a0\u5230 <code>batch<\/code> \u65f6\uff0c\u5bf9\u4e8e\u4f7f\u7528 firestore <code>servertimstamp<\/code> \u529f\u80fd\u7684\u5bf9\u8c61\uff0c\u5b83\u4f1a\u82b1\u8d39 2 \u6b21\u5199\u5165\u64cd\u4f5c\uff0c\u800c\u4e0d\u662f 1 \u6b21\u3002 \u627e\u4e0d\u5230\u4efb\u4f55\u76f8\u5173\u6587\u6863\u3002 \u95ee\u9898\u662f\uff0c\u5982\u679c\u60a8\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u672c\u5730\u8ba1\u6570\u5668\u5305\u88c5 firestore \u6279\u5904\u7406\uff0c\u4e3a\u907f\u514d\u8fbe\u5230 500 \u9608\u503c\uff0c\u60a8\u53ef\u80fd\u4f1a\u9519\u8bef\u8ba1\u7b97\u6279\u5904\u7406\u5927\u5c0f\u3002<\/p>\n<p>\u5728\u6211\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4f7f\u7528 golang firestore sdk\uff08\u4f46\u6211\u786e\u5b9e\u76f8\u4fe1\u8fd9\u4e2a\u95ee\u9898\u5bf9\u4e8e\u6240\u6709\u5176\u4ed6 sdk \u6765\u8bf4\u90fd\u5f88\u5e38\u89c1\uff0c\u56e0\u4e3a\u5b83\u6e90\u81ea firestore \u57fa\u672c\u673a\u5236\uff09<\/p>\n<pre>batch.Set(ctx, docRef, struct {\n    LastUpdate time.Time `firestore:\"lastUpdate,serverTimestamp\"`\n}{}, firestore.MergeAll)\n\n--&gt; batch.writes was increased by 2 writes rather than 1<\/pre>\n<p>\u6211\u7684\u95ee\u9898\u662f &#8211; \u662f\u5426\u6709\u4efb\u4f55\u5176\u4ed6\u7279\u6b8a\u7684 firestore \u503c\/\u64cd\u4f5c\u7b49\u53ef\u80fd\u4e5f\u9700\u8981\u8fdb\u884c\u8d85\u8fc7 1 \u6b21\u6279\u91cf\u5199\u5165\u64cd\u4f5c\uff1f \u8fd8\u6709\u4eba\u53ef\u4ee5\u5efa\u8bae\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u65b9\u6cd5\u5417\uff1f<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u6240\u8c13\u7684\u5b57\u6bb5\u8f6c\u6362\u64cd\u4f5c\u786e\u5b9e\u53ef\u80fd\u9700\u8981\u5728\u670d\u52a1\u5668\u4e0a\u6267\u884c\u591a\u4e2a\u5199\u5165\u64cd\u4f5c\uff0c\u4ece\u800c\u51cf\u5c11\u4e86\u53ef\u4ee5\u5728\u6279\u91cf\u5199\u5165\u6216\u4e8b\u52a1\u4e2d\u6267\u884c\u7684\u903b\u8f91\u5199\u5165\u64cd\u4f5c\u7684\u5bb9\u91cf\u3002\u5982\u679c\u6211\u6ca1\u8bb0\u9519\u7684\u8bdd\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ea\u9700\u4e3a\u4e00\u6b21\u5199\u5165\u64cd\u4f5c<em>\u4ed8\u8d39<\/em>\u3002<\/p>\n<p>\u4ece\u6211\u4e4b\u524d\u7ed9\u7684\u7b54\u6848\u6765\u770b\uff0c\u53ef\u7528\u7684\u4f3c\u4e4e\u662f<code>setToServerValue<\/code>\uff08\u60a8\u4f7f\u7528\u7684\u670d\u52a1\u5668\u65f6\u95f4\u6233\uff09\uff0c<code>increment<\/code>\uff0c<code>appendMissingElements<\/code>\uff0c<code>removeAllFromArray<\/code>\uff0czqbcz qbmaximum \u548c <code>minimum<\/code>\u3002\u6211\u4e0d\u786e\u5b9a\u6700\u540e\u4e24\u4e2a\u662f\u5426\u5df2\u5728\u4efb\u4f55 SDK \u4e0a\u516c\u5f00\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-206990","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=206990"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206990\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}