Mongoose and MongoDB patterns — schema design, validation, indexes, virtuals,
99
99%
Does it follow best practices?
Impact
100%
1.11xAverage score across 5 eval scenarios
Passed
No known issues
{
"context": "The agent implements a fund transfer function that must atomically update two wallet documents. Criteria check whether the agent correctly uses Mongoose transactions (startSession, withTransaction), passes the session to all operations, and cleans up the session in a finally block.",
"type": "weighted_checklist",
"checklist": [
{
"name": "startSession called",
"description": "The transfer function calls `mongoose.startSession()` (or equivalent) to create a session before beginning the transaction",
"max_score": 12
},
{
"name": "withTransaction used",
"description": "The transfer function uses `session.withTransaction(...)` to wrap the atomic operations rather than manually calling `session.startTransaction()` and `session.commitTransaction()`",
"max_score": 14
},
{
"name": "session passed to debit",
"description": "The debit (decrement balance on fromUserId) update operation receives `{ session }` in its options",
"max_score": 12
},
{
"name": "session passed to credit",
"description": "The credit (increment balance on toUserId) update operation receives `{ session }` in its options",
"max_score": 12
},
{
"name": "endSession in finally",
"description": "The transfer function calls `session.endSession()` inside a `finally` block so the session is always released, even if an error is thrown",
"max_score": 14
},
{
"name": "no independent updates",
"description": "The two balance update operations are NOT performed as plain independent awaits outside of a transaction (i.e., not two separate updateOne calls without a session)",
"max_score": 10
},
{
"name": "timestamps on Wallet schema",
"description": "The Wallet schema uses `timestamps: true` in its schema options",
"max_score": 7
},
{
"name": "required on wallet fields",
"description": "The `userId` and `balanceCents` fields on the Wallet schema are marked with `required: true`",
"max_score": 7
},
{
"name": "balanceCents minimum",
"description": "The `balanceCents` field on the Wallet schema has a `min: 0` constraint",
"max_score": 6
},
{
"name": "runValidators on updates",
"description": "Any update calls within the transaction pass `{ runValidators: true }` in the options",
"max_score": 6
}
]
}