{
  "openapi": "3.1.0",
  "info": {
    "title": "Data API",
    "version": "1.0.0",
    "description": "MongoDB-style access to a database stored in Google Drive. Every call is `POST /v1/db/{dbId}/{action}` with a JSON body, authenticated with the key from a connection string."
  },
  "servers": [
    {
      "url": "https://{host}",
      "variables": {
        "host": {
          "default": "your-app-domain",
          "description": "The host in your connection string."
        }
      }
    }
  ],
  "security": [
    {
      "bearerAuth": []
    },
    {
      "basicAuth": []
    }
  ],
  "tags": [
    {
      "name": "Read",
      "description": "Queries. Allowed with read-only keys."
    },
    {
      "name": "Write",
      "description": "Inserts, updates and deletes."
    },
    {
      "name": "Schema",
      "description": "Collections, fields and unique indexes."
    },
    {
      "name": "Realtime",
      "description": "Change streams."
    }
  ],
  "paths": {
    "/v1/db/{dbId}/find": {
      "post": {
        "operationId": "find",
        "tags": [
          "Read"
        ],
        "summary": "Find documents",
        "description": "Returns up to `limit` (max 1,000) matching documents. When `hasMore` is true, call again with `skip` increased by the number of documents received.",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "projection": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "Fields to include or exclude"
                  },
                  "sort": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "number",
                          "const": 1
                        },
                        {
                          "type": "number",
                          "const": -1
                        }
                      ]
                    },
                    "description": "Sort order, e.g. { \"dealValue\": -1 }"
                  },
                  "skip": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1000
                  },
                  "populate": {
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "readConcern": {
                    "description": "\"local\" skips the check for changes made in the app (faster, maybe a few seconds stale)",
                    "type": "string",
                    "enum": [
                      "fresh",
                      "local"
                    ]
                  }
                },
                "required": [
                  "collection"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "documents": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "description": "A document: `_id`, `_createdAt`, `_updatedAt` and your fields by API name.",
                        "properties": {
                          "_id": {
                            "type": "string"
                          },
                          "_createdAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "_updatedAt": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "additionalProperties": true
                      }
                    },
                    "hasMore": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "documents",
                    "hasMore"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/findOne": {
      "post": {
        "operationId": "findOne",
        "tags": [
          "Read"
        ],
        "summary": "Find one document",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "projection": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "Fields to include or exclude"
                  },
                  "sort": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "number",
                          "const": 1
                        },
                        {
                          "type": "number",
                          "const": -1
                        }
                      ]
                    },
                    "description": "Sort order, e.g. { \"dealValue\": -1 }"
                  },
                  "populate": {
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "readConcern": {
                    "description": "\"local\" skips the check for changes made in the app (faster, maybe a few seconds stale)",
                    "type": "string",
                    "enum": [
                      "fresh",
                      "local"
                    ]
                  }
                },
                "required": [
                  "collection"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "document": {
                      "oneOf": [
                        {
                          "type": "object",
                          "description": "A document: `_id`, `_createdAt`, `_updatedAt` and your fields by API name.",
                          "properties": {
                            "_id": {
                              "type": "string"
                            },
                            "_createdAt": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "_updatedAt": {
                              "type": "string",
                              "format": "date-time"
                            }
                          },
                          "additionalProperties": true
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "document"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/countDocuments": {
      "post": {
        "operationId": "countDocuments",
        "tags": [
          "Read"
        ],
        "summary": "Count documents",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "readConcern": {
                    "description": "\"local\" skips the check for changes made in the app (faster, maybe a few seconds stale)",
                    "type": "string",
                    "enum": [
                      "fresh",
                      "local"
                    ]
                  }
                },
                "required": [
                  "collection"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "count"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/distinct": {
      "post": {
        "operationId": "distinct",
        "tags": [
          "Read"
        ],
        "summary": "Distinct values of a field",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "key": {
                    "type": "string",
                    "minLength": 1
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "readConcern": {
                    "description": "\"local\" skips the check for changes made in the app (faster, maybe a few seconds stale)",
                    "type": "string",
                    "enum": [
                      "fresh",
                      "local"
                    ]
                  }
                },
                "required": [
                  "collection",
                  "key"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "values": {
                      "type": "array",
                      "items": {}
                    }
                  },
                  "required": [
                    "values"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/aggregate": {
      "post": {
        "operationId": "aggregate",
        "tags": [
          "Read"
        ],
        "summary": "Run an aggregation pipeline",
        "description": "Supports `$match`, `$project`, `$addFields`/`$set`, `$unset`, `$group`, `$sort`, `$skip`, `$limit`, `$count`, `$unwind`, `$lookup` (by collection API name) and `$sortByCount`. `$out` and `$merge` are not available.",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "pipeline": {
                    "maxItems": 50,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {}
                    }
                  },
                  "readConcern": {
                    "description": "\"local\" skips the check for changes made in the app (faster, maybe a few seconds stale)",
                    "type": "string",
                    "enum": [
                      "fresh",
                      "local"
                    ]
                  }
                },
                "required": [
                  "collection",
                  "pipeline"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "documents": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  },
                  "required": [
                    "documents"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/listCollections": {
      "post": {
        "operationId": "listCollections",
        "tags": [
          "Read"
        ],
        "summary": "List collections",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "readConcern": {
                    "description": "\"local\" skips the check for changes made in the app (faster, maybe a few seconds stale)",
                    "type": "string",
                    "enum": [
                      "fresh",
                      "local"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "collections": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CollectionInfo"
                      }
                    }
                  },
                  "required": [
                    "collections"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/getSchema": {
      "post": {
        "operationId": "getSchema",
        "tags": [
          "Read"
        ],
        "summary": "Describe a collection",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "readConcern": {
                    "description": "\"local\" skips the check for changes made in the app (faster, maybe a few seconds stale)",
                    "type": "string",
                    "enum": [
                      "fresh",
                      "local"
                    ]
                  }
                },
                "required": [
                  "collection"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "collection": {
                      "$ref": "#/components/schemas/CollectionInfo"
                    }
                  },
                  "required": [
                    "collection"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/listIndexes": {
      "post": {
        "operationId": "listIndexes",
        "tags": [
          "Read"
        ],
        "summary": "List indexes",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "readConcern": {
                    "description": "\"local\" skips the check for changes made in the app (faster, maybe a few seconds stale)",
                    "type": "string",
                    "enum": [
                      "fresh",
                      "local"
                    ]
                  }
                },
                "required": [
                  "collection"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "indexes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "key": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "integer"
                            }
                          },
                          "unique": {
                            "type": "boolean"
                          }
                        },
                        "required": [
                          "name",
                          "key",
                          "unique"
                        ]
                      }
                    }
                  },
                  "required": [
                    "indexes"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/insertOne": {
      "post": {
        "operationId": "insertOne",
        "tags": [
          "Write"
        ],
        "summary": "Insert a document",
        "description": "Unknown fields are created automatically, with their type guessed from the value. A missing `_id` is generated; a string `_id` you choose is kept.",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "document": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "A document"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "document"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "insertedId": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "insertedId"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/insertMany": {
      "post": {
        "operationId": "insertMany",
        "tags": [
          "Write"
        ],
        "summary": "Insert documents",
        "description": "Up to 1,000 documents. All are inserted, or none (for example on a duplicate unique value).",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "documents": {
                    "minItems": 1,
                    "maxItems": 1000,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "A document"
                    }
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "documents"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "insertedIds": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "insertedCount": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "insertedIds",
                    "insertedCount"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/updateOne": {
      "post": {
        "operationId": "updateOne",
        "tags": [
          "Write"
        ],
        "summary": "Update one document",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "update": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "A document"
                  },
                  "upsert": {
                    "type": "boolean"
                  },
                  "sort": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "number",
                          "const": 1
                        },
                        {
                          "type": "number",
                          "const": -1
                        }
                      ]
                    },
                    "description": "Sort order, e.g. { \"dealValue\": -1 }"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "filter",
                  "update"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "matchedCount": {
                      "type": "integer"
                    },
                    "modifiedCount": {
                      "type": "integer"
                    },
                    "upsertedId": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "matchedCount",
                    "modifiedCount"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/updateMany": {
      "post": {
        "operationId": "updateMany",
        "tags": [
          "Write"
        ],
        "summary": "Update documents",
        "description": "All matching documents are updated together, or none if any update is invalid.",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "update": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "A document"
                  },
                  "upsert": {
                    "type": "boolean"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "filter",
                  "update"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "matchedCount": {
                      "type": "integer"
                    },
                    "modifiedCount": {
                      "type": "integer"
                    },
                    "upsertedId": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "matchedCount",
                    "modifiedCount"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/replaceOne": {
      "post": {
        "operationId": "replaceOne",
        "tags": [
          "Write"
        ],
        "summary": "Replace a document",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "replacement": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "A document"
                  },
                  "upsert": {
                    "type": "boolean"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "filter",
                  "replacement"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "matchedCount": {
                      "type": "integer"
                    },
                    "modifiedCount": {
                      "type": "integer"
                    },
                    "upsertedId": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "matchedCount",
                    "modifiedCount"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/deleteOne": {
      "post": {
        "operationId": "deleteOne",
        "tags": [
          "Write"
        ],
        "summary": "Delete one document",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "filter"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deletedCount": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "deletedCount"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/deleteMany": {
      "post": {
        "operationId": "deleteMany",
        "tags": [
          "Write"
        ],
        "summary": "Delete documents",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "filter"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deletedCount": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "deletedCount"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/findOneAndUpdate": {
      "post": {
        "operationId": "findOneAndUpdate",
        "tags": [
          "Write"
        ],
        "summary": "Update a document and return it",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "update": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "A document"
                  },
                  "upsert": {
                    "type": "boolean"
                  },
                  "sort": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "number",
                          "const": 1
                        },
                        {
                          "type": "number",
                          "const": -1
                        }
                      ]
                    },
                    "description": "Sort order, e.g. { \"dealValue\": -1 }"
                  },
                  "projection": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "Fields to include or exclude"
                  },
                  "returnDocument": {
                    "type": "string",
                    "enum": [
                      "before",
                      "after"
                    ]
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "filter",
                  "update"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "document": {
                      "oneOf": [
                        {
                          "type": "object",
                          "description": "A document: `_id`, `_createdAt`, `_updatedAt` and your fields by API name.",
                          "properties": {
                            "_id": {
                              "type": "string"
                            },
                            "_createdAt": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "_updatedAt": {
                              "type": "string",
                              "format": "date-time"
                            }
                          },
                          "additionalProperties": true
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "document"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/findOneAndDelete": {
      "post": {
        "operationId": "findOneAndDelete",
        "tags": [
          "Write"
        ],
        "summary": "Delete a document and return it",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "filter": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "MongoDB query filter"
                  },
                  "sort": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "number",
                          "const": 1
                        },
                        {
                          "type": "number",
                          "const": -1
                        }
                      ]
                    },
                    "description": "Sort order, e.g. { \"dealValue\": -1 }"
                  },
                  "projection": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "Fields to include or exclude"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "filter"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "document": {
                      "oneOf": [
                        {
                          "type": "object",
                          "description": "A document: `_id`, `_createdAt`, `_updatedAt` and your fields by API name.",
                          "properties": {
                            "_id": {
                              "type": "string"
                            },
                            "_createdAt": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "_updatedAt": {
                              "type": "string",
                              "format": "date-time"
                            }
                          },
                          "additionalProperties": true
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "document"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/bulkWrite": {
      "post": {
        "operationId": "bulkWrite",
        "tags": [
          "Write"
        ],
        "summary": "Several writes, all or nothing",
        "description": "Operations are checked against a copy first and applied together: if one fails, nothing changes. Each operation is `{ insertOne | updateOne | updateMany | replaceOne | deleteOne | deleteMany: {...} }`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "operations": {
                    "minItems": 1,
                    "maxItems": 1000,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {}
                    }
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "operations"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "insertedCount": {
                      "type": "integer"
                    },
                    "matchedCount": {
                      "type": "integer"
                    },
                    "modifiedCount": {
                      "type": "integer"
                    },
                    "deletedCount": {
                      "type": "integer"
                    },
                    "upsertedCount": {
                      "type": "integer"
                    },
                    "insertedIds": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "string"
                      }
                    },
                    "upsertedIds": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "insertedCount",
                    "matchedCount",
                    "modifiedCount",
                    "deletedCount",
                    "upsertedCount",
                    "insertedIds",
                    "upsertedIds"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/createCollection": {
      "post": {
        "operationId": "createCollection",
        "tags": [
          "Schema"
        ],
        "summary": "Create a collection",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "displayName": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "fields": {
                    "maxItems": 200,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "API name of the field"
                        },
                        "type": {
                          "type": "string",
                          "enum": [
                            "text",
                            "longText",
                            "number",
                            "date",
                            "checkbox",
                            "singleSelect",
                            "multiSelect",
                            "url",
                            "email",
                            "phone",
                            "json",
                            "link"
                          ]
                        },
                        "displayName": {
                          "type": "string",
                          "maxLength": 200
                        },
                        "options": {
                          "type": "object",
                          "properties": {
                            "numberFormat": {
                              "type": "string",
                              "enum": [
                                "plain",
                                "currency",
                                "percent"
                              ]
                            },
                            "decimals": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 8
                            },
                            "currency": {
                              "type": "string",
                              "maxLength": 8
                            },
                            "includeTime": {
                              "type": "boolean"
                            },
                            "choices": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "name": {
                                    "type": "string"
                                  },
                                  "color": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "name",
                                  "color"
                                ]
                              }
                            },
                            "linkedCollection": {
                              "type": "string"
                            },
                            "multiple": {
                              "type": "boolean"
                            },
                            "unique": {
                              "type": "boolean"
                            }
                          }
                        }
                      },
                      "required": [
                        "name",
                        "type"
                      ]
                    }
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "collection": {
                      "$ref": "#/components/schemas/CollectionInfo"
                    }
                  },
                  "required": [
                    "collection"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/dropCollection": {
      "post": {
        "operationId": "dropCollection",
        "tags": [
          "Schema"
        ],
        "summary": "Drop a collection",
        "description": "The collection (table) moves to \"Recently deleted\" in the app, where it can be restored.",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "dropped": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "dropped"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/createIndex": {
      "post": {
        "operationId": "createIndex",
        "tags": [
          "Schema"
        ],
        "summary": "Create an index (unique fields)",
        "description": "A unique single-field index makes the field unique (checked on every write). Other indexes are accepted for driver compatibility and change nothing: queries run in memory.",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "keys": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "number",
                          "const": 1
                        },
                        {
                          "type": "number",
                          "const": -1
                        }
                      ]
                    }
                  },
                  "unique": {
                    "type": "boolean"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "keys"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "name"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/dropIndex": {
      "post": {
        "operationId": "dropIndex",
        "tags": [
          "Schema"
        ],
        "summary": "Drop an index",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "collection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "Collection (table) API name"
                  },
                  "name": {
                    "type": "string"
                  },
                  "writeConcern": {
                    "description": "{ w: \"drive\" } waits until the change is saved to Google Drive",
                    "type": "object",
                    "properties": {
                      "w": {
                        "type": "string",
                        "enum": [
                          "log",
                          "drive"
                        ]
                      }
                    }
                  }
                },
                "required": [
                  "collection",
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "dropped": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "dropped"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          },
          "507": {
            "$ref": "#/components/responses/E507"
          }
        }
      }
    },
    "/v1/db/{dbId}/watch": {
      "get": {
        "operationId": "watch",
        "tags": [
          "Realtime"
        ],
        "summary": "Follow changes (Server-Sent Events)",
        "description": "A `text/event-stream` of `change` events (`insert`, `update`, `delete`). API writes arrive at once, edits made in the app within about 5 seconds. A `ready` event marks the start; streams end after an hour with an `end` event, so reconnect.",
        "parameters": [
          {
            "$ref": "#/components/parameters/dbId"
          },
          {
            "name": "collection",
            "in": "query",
            "required": false,
            "description": "Only changes in this collection (all collections when omitted).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The event stream.",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "The key part of your connection string: `kid_…:sk_…`."
      },
      "basicAuth": {
        "type": "http",
        "scheme": "basic",
        "description": "User name: the key id (`kid_…`). Password: the secret (`sk_…`). Handy in Zapier, Make and n8n."
      }
    },
    "parameters": {
      "dbId": {
        "name": "dbId",
        "in": "path",
        "required": true,
        "description": "The database id (the last part of the connection string).",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "CollectionInfo": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "API name"
          },
          "displayName": {
            "type": "string",
            "description": "Name shown in the app"
          },
          "count": {
            "type": "integer"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "displayName": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                },
                "unique": {
                  "type": "boolean"
                },
                "linkedCollection": {
                  "type": "string"
                },
                "multiple": {
                  "type": "boolean"
                },
                "choices": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "name",
                "displayName",
                "type",
                "unique"
              ]
            }
          }
        },
        "required": [
          "name",
          "displayName",
          "count",
          "fields"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object",
                "additionalProperties": true
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      }
    },
    "responses": {
      "E400": {
        "description": "Invalid request (`BadRequest`, `ValidationError`, `BadValue`, `ImmutableField`, `InvalidName`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E401": {
        "description": "Missing, wrong, revoked or expired connection string, or Google access was removed (`Unauthorized`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E403": {
        "description": "Read-only connection string (`ReadOnlyKey`) or a database you can only view (`ReadOnly`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E404": {
        "description": "Unknown collection (`NamespaceNotFound`) or action (`UnknownAction`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E409": {
        "description": "A unique field already has this value (`DuplicateKey`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E413": {
        "description": "Request body over 1 MB (`PayloadTooLarge`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E429": {
        "description": "Too many requests (`RateLimited`). Wait for `Retry-After` seconds.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E503": {
        "description": "The database file is unavailable (`DatabaseUnavailable`) or Google Drive is busy (`DriveUnavailable`, retry).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E507": {
        "description": "The owner’s Google Drive is full (`DriveFull`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
