{"id":300742,"date":"2021-01-17T12:54:32","date_gmt":"2021-01-17T04:54:32","guid":{"rendered":"http:\/\/4563.org\/?p=300742"},"modified":"2021-01-17T12:54:32","modified_gmt":"2021-01-17T04:54:32","slug":"golang-mongo-driver-%e5%a6%82%e4%bd%95%e6%9b%b4%e6%96%b0%e6%9f%90%e4%b8%aa%e5%ad%97%e6%ae%b5","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=300742","title":{"rendered":"golang mongo-driver \u5982\u4f55\u66f4\u65b0\u67d0\u4e2a\u5b57\u6bb5"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  golang mongo-driver \u5982\u4f55\u66f4\u65b0\u67d0\u4e2a\u5b57\u6bb5               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aoscici <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code> type Comment struct {  ID      primitive.ObjectID `bson:\"_id,omitempty\"  json:\"id\"`  Title   string             `bson:\"title\"          json:\"title\"       binding:\"required\"`  Author  string             `bson:\"author\"         json:\"author\"      binding:\"required\"`  Content string             `bson:\"content\"        json:\"content\"     binding:\"required\"`  Like    int64              `bson:\"like\"           json:\"like\"`  Updated time.Time          `bson:\"updated\"        json:\"updated\"` }  Collection.FindOneAndUpdate(ctx, filter, update, &amp;opt).Decode(&amp;comment)  <\/code><\/pre>\n<p>\u6bd4\u5982\u8fd9\u91cc\u6211\u53ea\u4f20\u6765 {&#8220;content&#8221;: &#8220;\u3002\u3002\u3002&#8221;} \u6216\u8005 {&#8220;author&#8221;: &#8220;11&#8221;} \u8fd9\u4e00\u4e2a\u6570\u636e\uff0c\u600e\u4e48\u7075\u6d3b\u5f97\u63a5\u6536\u8fd9\u4e2a\u6570\u636e\u548c\u53ea\u66f4\u65b0\u8fd9\u4e00\u4e2a\u5b57\u6bb5\uff1f\u7ffb\u4e86\u5f88\u591a\u6587\u7ae0\u8c8c\u4f3c\u90fd\u662f\u628a\u66f4\u65b0\u9879\u5199\u6b7b\u7684\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5079683\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : teawithlife <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u4e0d\u786e\u5b9a\u662f\u5426\u6709\u8fd9\u6837\u7684\u529f\u80fd\uff0c\u4f46\u662f\u4ece\u9053\u7406\u4e0a\u6765\u8bf4\uff0c\u4e00\u4e2a API \u7684\u8bbe\u8ba1\uff0c\u9700\u8981\u66f4\u65b0\u54ea\u4e9b\u5b57\u6bb5\u5e94\u8be5\u662f\u660e\u786e\u7684\uff0c\u4e0d\u5e94\u8be5\u968f\u610f\u53d8\u5316\u3002\u6240\u4ee5\u6211\u6000\u7591\u4f60\u8fd9\u662f\u4e00\u4e2a XY \u95ee\u9898\uff0c\u53ef\u5426\u5148\u8bb2\u8bb2\u4f60\u8fd9\u4e2a\u9700\u6c42\u4ea7\u751f\u7684\u539f\u56e0\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079684\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lithiumii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u76f4\u63a5\uff5b&#8217;$set&#8217;:{&#8216;content&#8217;: &#8216;&#8230;&#8217;}\uff5d\u5c31\u884c\u4e86\u5427\uff0c\u6ca1\u6d89\u53ca\u7684\u5b57\u6bb5\u4e0d\u4f1a\u53d8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079685\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : aoscici <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @teawithlife \u6bd4\u5982\u8bf4\u6211\u5c31\u5355\u72ec\u66f4\u65b0\u4e00\u4e0b\u4e2a\u4eba\u4fe1\u606f\u7684\u5e74\u9f84\uff0c\u6216\u8005\u5355\u72ec\u66f4\u65b0\u6027\u522b\uff0c\u4e0d\u77e5\u9053\u8be5\u600e\u4e48\u64cd\u4f5c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079686\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : aoscici <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lithiumii \u4e3b\u8981\u662f\u6211\u60f3\u80fd\u4e0d\u80fd\u5355\u72ec\u4f20\u4e00\u4e2a\u5b57\u6bb5\u8fdb\u6765\uff0c\u5c31\u66f4\u65b0\u8fd9\u4e2a\u5b57\u6bb5\uff0c\u800c\u4e0d\u662f\u6240\u6709 required \u7684\u5b57\u6bb5\u90fd\u8981\u4f20                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079687\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bankroft <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u63a5\u6536 bson.M\uff0cset bsonM \u4e0d\u884c\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079688\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : useben <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5916\u90e8\u4f20\u5165 map[string]interface{}\u53c2\u6570\uff0c \u5185\u90e8\u521b\u5efa bson.M\uff0c\u904d\u5386 map[string]interface{}\u8d4b\u503c bson.M\uff0c \u6700\u540e set bsonM                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079689\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yeqown <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @useben \u8fd9\u79cd\u65b9\u5f0f\u53ef\u884c, \u8865\u5145\u4e00\u70b9\uff1a\u4e0d\u63a8\u8350\u76f4\u63a5\u4f7f\u7528 map[string]interface{} \uff0c\u53ef\u4ee5\u8003\u8651\u4ece\u6a21\u578b struct \u8f6c\u8fc7\u6765\uff0c\u90a3\u6837\u5c31\u4e0d\u7528\u5173\u5fc3\u6570\u636e\u5e93\u91cc\u5b57\u6bb5\u540d\u662f\u4ec0\u4e48\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079690\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : useben <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @yeqown \u4e5f\u53ef\u4ee5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079691\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : aoscici <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @useben \u8c22\u8c22\uff0c\u770b\u7740\u53ef\u884c\u54c8\u54c8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>golang mongo-driv&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/300742"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=300742"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/300742\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300742"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}