CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/mongoose-best-practices

Mongoose and MongoDB patterns — schema design, validation, indexes, virtuals,

99

1.11x
Quality

99%

Does it follow best practices?

Impact

100%

1.11x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

criteria.jsonevals/scenario-4/

{
  "context": "The agent implements a product catalog data layer with read-only listing, admin updates with validation, and price updates that must trigger a pre-save hook. Criteria check whether lean() is used for read-only results, runValidators is passed on updates, and the correct save() pattern is used to ensure pre-save hooks fire during price updates.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "lean on listProducts",
      "description": "The `listProducts` function applies `.lean()` to the Mongoose query before returning results (since results go to API responses and are read-only)",
      "max_score": 12
    },
    {
      "name": "no lean on updateProductPrice",
      "description": "The `updateProductPrice` function does NOT use `.lean()` when fetching the document, since it needs to call `.save()` on the result",
      "max_score": 8
    },
    {
      "name": "runValidators on admin update",
      "description": "The `updateProductAdmin` function passes `{ runValidators: true }` in the options object of its update call",
      "max_score": 14
    },
    {
      "name": "save() for price update",
      "description": "The `updateProductPrice` function uses `document.save()` (fetch-then-save pattern) rather than `findByIdAndUpdate` or `updateOne`, ensuring the pre-save hook fires",
      "max_score": 14
    },
    {
      "name": "no direct update for price",
      "description": "The `updateProductPrice` function does NOT use `findByIdAndUpdate`, `updateOne`, or similar update methods to set the new price (which would skip the hook)",
      "max_score": 10
    },
    {
      "name": "pre-save hook defined",
      "description": "A `pre('save')` hook is registered on the Product schema to compute `discountedPriceCents`",
      "max_score": 8
    },
    {
      "name": "enum for status",
      "description": "The Product schema defines `status` as a field with an `enum` constraint listing valid values",
      "max_score": 8
    },
    {
      "name": "required fields",
      "description": "At least `name`, `status`, `basePriceCents`, and `stock` are marked with `required: true`",
      "max_score": 7
    },
    {
      "name": "timestamps option",
      "description": "The Product schema uses `timestamps: true` in schema options",
      "max_score": 7
    },
    {
      "name": "stock minimum constraint",
      "description": "The `stock` field in the schema has a `min: 0` constraint to prevent negative stock values",
      "max_score": 6
    },
    {
      "name": "new: true on admin update",
      "description": "If `updateProductAdmin` uses `findByIdAndUpdate` or `findOneAndUpdate`, it passes `{ new: true }` to return the modified document",
      "max_score": 6
    }
  ]
}

evals

tile.json