小编use*_*987的帖子

MongoDB更新验证器

我有一个看起来像这样的集合:

{
  "_id": "5c90e8736441c96cc8e5c703",
  "meta": {
    "schemaVersion": 1,
    "locHint": {
      "region": "150",
      "country": "GBR"
    }
  },
  "name": "My test study"
}
Run Code Online (Sandbox Code Playgroud)

和以下验证器:

{
  "$jsonSchema": {
    "bsonType": "object",
    "required": [
      "meta.schemaVersion"
      "meta.locHint.region",
      "meta.locHint.country",
      "name"
    ],
    "properties": {
      "meta.schemaVersion": {
        "bsonType": "int",
        "description": "Version counter used schema changes"
      },
      "meta.locHint.region": {
        "bsonType": "string",
        "pattern": "^[0-9]{3}$",
        "description": "meta.locHint.region is required to be a valid iso3166 region  (3 digits)"
      },
      "meta.locHint.country": {
        "bsonType": "string",
        "pattern": "^[A-Z]{3}$",
        "description": "meta.locHint.country is required to be a valid …
Run Code Online (Sandbox Code Playgroud)

mongodb mongobee

7
推荐指数
1
解决办法
160
查看次数

标签 统计

mongobee ×1

mongodb ×1