KeplerGrid guide

Test MongoDB $jsonSchema validation with a typed edit

Create the validator in mongosh, then test it in KeplerGrid. A Decimal128 price passes the rule. A text price is rejected when you commit the edit.

Create a fresh collection with a validator

Run this once in mongosh against a disposable MongoDB instance using an account that can create and write the collection. The rule requires a non-negative Decimal128 unitPrice.

const lab = db.getSiblingDB("keplergrid_validation")
lab.createCollection("products", {
  validator: {
    $jsonSchema: {
      bsonType: "object",
      required: ["unitPrice"],
      properties: {
        unitPrice: {
          bsonType: "decimal",
          minimum: 0
        }
      }
    }
  },
  validationLevel: "strict",
  validationAction: "error"
})
lab.products.insertOne({
  _id: "SKU-101",
  name: "Notebook",
  unitPrice: Decimal128("12.50")
})

Stage and commit a Decimal128 edit

  1. Connect KeplerGrid to the practice server in Read & write mode. Open keplergrid_validation.products and run the filter { "_id": "SKU-101" } with an empty projection.
  2. Select the row. In the document inspector, choose Extended JSON and replace only the unitPrice value with the Extended JSON below.
  3. Select Stage document changes, then Review & commit. Confirm the destination and the proposed value, then select Commit 1 document.
{ "$numberDecimal": "12.75" }

Rerun the filter and confirm the stored price is now Decimal128 12.75.

Try the same price as text

In the practice collection, repeat the edit using the JSON string "12.75" as unitPrice. Review the proposed type change and commit. The validator runs on the server at commit time. KeplerGrid reports MongoDB document validation rejected the change.

Discard the rejected local draft, then rerun the filter and inspect the stored value again. It should still be { "$numberDecimal": "12.75" }. If the rejection in your own database has another cause, compare the collection’s validator with the whole proposed document, including required fields.

See the Decimal128 editing workflow or map CSV columns to BSON types before import.

For an existing collection, audit the stored BSON types before choosing the expected type.