{"id":21620,"date":"2024-01-02T12:31:22","date_gmt":"2024-01-02T12:31:22","guid":{"rendered":"https:\/\/server.hk\/blog\/21620\/"},"modified":"2024-11-14T10:29:40","modified_gmt":"2024-11-14T02:29:40","slug":"how-to-fix-mongodb-error-code-25-remotevalidationerror","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21620\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 25 &#8211; RemoteValidationError"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-25-remotevalidationerror-ppHUuNSOaP\">\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 25 &#8211; RemoteValidationError<\/h1>\n<p>MongoDB \u662f\u4e00\u500b\u53d7\u6b61\u8fce\u7684 NoSQL \u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u9ad8\u6548\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u53ca\u9748\u6d3b\u6027\u3002\u7136\u800c\uff0c\u8207\u5176\u4ed6\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u9700\u8981\u89e3\u6c7a\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 25 &#8211; RemoteValidationError\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u542b\u7fa9\u53ca\u5176\u4fee\u5fa9\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"understanding-mongodb-error-code-25-remotevalidationerror-ppHUuNSOaP\">\u4e86\u89e3 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 25 &#8211; RemoteValidationError<\/h2>\n<p>MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 25 &#8211; RemoteValidationError \u767c\u751f\u5728\u9060\u7aef\u4f3a\u670d\u5668\u51fa\u73fe\u9a57\u8b49\u932f\u8aa4\u6642\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u767c\u751f\u5728\u4f60\u5617\u8a66\u63d2\u5165\u6216\u66f4\u65b0\u9055\u53cd\u96c6\u5408\u4e2d\u5df2\u5b9a\u7fa9\u7684\u9a57\u8b49\u898f\u5247\u7684\u6587\u6a94\u6642\u3002<\/p>\n<p>\u7576\u4f60\u5728 MongoDB \u4e2d\u5b9a\u7fa9\u4e00\u500b\u96c6\u5408\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528 JSON Schema \u6307\u5b9a\u9a57\u8b49\u898f\u5247\u3002\u9019\u4e9b\u898f\u5247\u5b9a\u7fa9\u4e86\u53ef\u4ee5\u63d2\u5165\u6216\u66f4\u65b0\u5230\u96c6\u5408\u4e2d\u7684\u6587\u6a94\u7684\u7d50\u69cb\u548c\u5167\u5bb9\u3002\u5982\u679c\u6587\u6a94\u9055\u53cd\u4e86\u9019\u4e9b\u898f\u5247\uff0cMongoDB \u6703\u62cb\u51fa RemoteValidationError \u932f\u8aa4\u3002<\/p>\n<h2 id=\"fixing-mongodb-error-code-25-remotevalidationerror-ppHUuNSOaP\">\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 25 &#8211; RemoteValidationError<\/h2>\n<p>\u8981\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 25 &#8211; RemoteValidationError\uff0c\u4f60\u9700\u8981\u8b58\u5225\u9a57\u8b49\u932f\u8aa4\u7684\u539f\u56e0\uff0c\u4e26\u5c0d\u6587\u6a94\u6216\u9a57\u8b49\u898f\u5247\u9032\u884c\u5fc5\u8981\u7684\u66f4\u6539\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u89e3\u6c7a\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-identify-the-document-causing-the-error-ppHUuNSOaP\">1. \u8b58\u5225\u5c0e\u81f4\u932f\u8aa4\u7684\u6587\u6a94<\/h3>\n<p>\u9996\u5148\u8981\u505a\u7684\u662f\u8b58\u5225\u5c0e\u81f4\u9a57\u8b49\u932f\u8aa4\u7684\u6587\u6a94\u3002\u4f60\u53ef\u4ee5\u901a\u904e\u6aa2\u67e5 MongoDB \u8fd4\u56de\u7684\u932f\u8aa4\u8a0a\u606f\u4f86\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002\u932f\u8aa4\u8a0a\u606f\u901a\u5e38\u5305\u542b\u6709\u95dc\u6587\u6a94\u53ca\u9055\u53cd\u7684\u9a57\u8b49\u898f\u5247\u7684\u76f8\u95dc\u8cc7\u8a0a\u3002<\/p>\n<h3 id=\"2-review-the-validation-rules-ppHUuNSOaP\">2. \u5be9\u67e5\u9a57\u8b49\u898f\u5247<\/h3>\n<p>\u7576\u4f60\u8b58\u5225\u5230\u6587\u6a94\u5f8c\uff0c\u8acb\u5be9\u67e5\u70ba\u96c6\u5408\u5b9a\u7fa9\u7684\u9a57\u8b49\u898f\u5247\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 MongoDB Shell \u4e2d\u7684 <code>db.getCollectionInfos()<\/code> \u547d\u4ee4\u4f86\u6aa2\u7d22\u96c6\u5408\u7684\u9a57\u8b49\u898f\u5247\u3002<\/p>\n<pre><code>db.getCollectionInfos({name: \"your_collection_name\"})\r\n<\/code><\/pre>\n<p>\u78ba\u4fdd\u9a57\u8b49\u898f\u5247\u5b9a\u7fa9\u6b63\u78ba\uff0c\u4e26\u4e14\u8207\u4f60\u5617\u8a66\u63d2\u5165\u6216\u66f4\u65b0\u7684\u6587\u6a94\u7684\u7d50\u69cb\u53ca\u5167\u5bb9\u5339\u914d\u3002<\/p>\n<h3 id=\"3-update-the-document-ppHUuNSOaP\">3. \u66f4\u65b0\u6587\u6a94<\/h3>\n<p>\u5982\u679c\u6587\u6a94\u9055\u53cd\u4e86\u9a57\u8b49\u898f\u5247\uff0c\u4f60\u9700\u8981\u66f4\u65b0\u5b83\u4ee5\u7b26\u5408\u898f\u5247\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>db.collection.update()<\/code> \u547d\u4ee4\u4f86\u4fee\u6539\u6587\u6a94\u3002<\/p>\n<pre><code>db.collection.update(\r\n   { _id: ObjectId(\"document_id\") },\r\n   { $set: { field1: \"new_value\" } }\r\n)\r\n<\/code><\/pre>\n<p>\u5c07 <code>collection<\/code> \u66ff\u63db\u70ba\u4f60\u7684\u96c6\u5408\u540d\u7a31\uff0c\u5c07 <code>document_id<\/code> \u66ff\u63db\u70ba\u5c0e\u81f4\u932f\u8aa4\u7684\u6587\u6a94 ID\uff0c\u4e26\u5c07 <code>field1<\/code> \u66ff\u63db\u70ba\u9700\u8981\u66f4\u65b0\u7684\u5b57\u6bb5\u3002<\/p>\n<h3 id=\"4-retry-the-operation-ppHUuNSOaP\">4. \u91cd\u8a66\u64cd\u4f5c<\/h3>\n<p>\u66f4\u65b0\u6587\u6a94\u5f8c\uff0c\u91cd\u8a66\u5c0e\u81f4\u932f\u8aa4\u7684\u64cd\u4f5c\u3002\u5982\u679c\u6587\u6a94\u73fe\u5728\u7b26\u5408\u9a57\u8b49\u898f\u5247\uff0c\u932f\u8aa4\u61c9\u4e0d\u518d\u767c\u751f\u3002<\/p>\n<h2 id=\"summary-ppHUuNSOaP\">\u7e3d\u7d50<\/h2>\n<p>MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 25 &#8211; RemoteValidationError \u662f\u4e00\u500b\u9a57\u8b49\u932f\u8aa4\uff0c\u767c\u751f\u5728\u6587\u6a94\u9055\u53cd\u96c6\u5408\u5b9a\u7fa9\u7684\u9a57\u8b49\u898f\u5247\u6642\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u4f60\u9700\u8981\u8b58\u5225\u5c0e\u81f4\u932f\u8aa4\u7684\u6587\u6a94\uff0c\u5be9\u67e5\u9a57\u8b49\u898f\u5247\uff0c\u5fc5\u8981\u6642\u66f4\u65b0\u6587\u6a94\uff0c\u4e26\u91cd\u8a66\u64cd\u4f5c\u3002\u5982\u679c\u4f60\u9700\u8981\u6709\u95dc MongoDB \u8a17\u7ba1\u7684\u5354\u52a9\u6216\u6709\u4efb\u4f55\u9032\u4e00\u6b65\u7684\u554f\u984c\uff0c\u96a8\u6642\u806f\u7e6b <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-21620","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21620","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=21620"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21620\/revisions"}],"predecessor-version":[{"id":23808,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21620\/revisions\/23808"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}