Docs
Search…
Schemas
Schemas define what kind of data a collection represents and how it is stored in your collection.
​
Batch currently supports three types of schemas:

JSON

JSON schemas require that the data payloads sent to your collection be valid JSON. We perform automatic schema inference on your payload, allowing you to add/exclude fields from your payloads as needed. No need to manually define or update your schema!
Advantages:
  • Fields can be added simply by including them in your payload. The schema will be inferred and updated automatically with no need for manual work on your part
  • Ideal for structured or semi-structured data
  • Allows querying of individual fields
  • Fields can be removed from your payloads, unlike protocol buffers
Disadvantages:
  • Type cannot be changed on a field once it has been observed
  • The type of a field (string, number, object, array, bool) must remain the same once the field is present in your collection
    • 1
      // EXAMPLE
      2
      ​
      3
      // Event 1 - GOOD
      4
      {
      5
      "foo": "string1",
      6
      "baz": [1, 2, 3]
      7
      }
      8
      ​
      9
      // A subsequent event CAN omit "baz"
      10
      ​
      11
      // Event 2 - GOOD
      12
      {
      13
      "foo": "boop"
      14
      }
      15
      ​
      16
      // A subsequent event CANNOT modify the type for "baz"
      17
      ​
      18
      // Event 3 - BAD
      19
      {
      20
      "foo": "beep",
      21
      "baz": "now it's a string"
      22
      }
      Copied!

Protocol Buffers

Protocol buffer schemas allow you to send binary protobuf messages directly to your collection. Batch will decode the messages using the .proto definitions you uploaded when creating the schema. There is no need to decode/transform the messages on your end before sending it to us!
Advantages:
  • Ideal for structured data
  • Allows querying of individual fields
Disadvantages:
  • Any updates to your protobuf definitions require you to re-upload them to Batch before we can accept messages containing new fields
​

Plain

Plain schemas are a catch-all for unstructured data. We do not perform schema inference on the contents your data. The contents of your data is not indexed, so fields within the data are not queryable, only the entire payload as a whole. For more structured data, we recommend using a JSON schema
Advantages:
  • Your data can be in any format
Disadvantages:
  • Data within the payloads cannot be queried

Schema Inspection

You can inspect the schema Batch has inferred in console.batch.sh.
  1. 1.
    Navigate to 'collections' section of the dashboard
  2. 2.
    Click the collection you wish to inspect
  3. 3.
    Select the sprocket at the top right
4. Scroll down until you reach the 'Schema' section
Last modified 2mo ago
Copy link