Mongodb datetrunc binsize zero guard
Skill kjuhwa/skills-hub/skills/backend/mongodb-datetrunc-binsize-zero-guard
Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.
npx -y skills add kjuhwa/skills-hub --skill mongodb-datetrunc-binsize-zero-guardAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Guard MongoDB $dateTrunc binSize against 0 when your interval may be auto/unset; coerce to 1 to avoid runtime error
SKILL.md
1.4 KB, 250 tokens by cl100k_base, as published. Nobody here has run it
mongodb-datetrunc-binsize-zero-guard
Rule
$dateTrunc.binSize must be >= 1. If your interval resolver returns 0 (e.g. "auto"
mode that is resolved later), coerce to 1 at construction time, never ship 0 to
MongoDB.
Pattern
int binSize = (interval == 0) ? 1 : interval;
Document dateTrunc = new Document("$dateTrunc", new Document()
.append("date", "$timestamp")
.append("unit", unit)
.append("binSize", binSize));
Why
MongoDB driver rejects binSize: 0 with a runtime error that surfaces only when the
aggregation executes — so it slips past unit tests using stubbed intervals. Found in
production via SonarQube/Jenkins build (commit 3ad4cf9).
How to apply
Whenever you have a chain userMode → intervalResolver → $dateTrunc, add the guard at
the repository/query-builder boundary, not in the resolver (resolver's "auto=0" may be
meaningful elsewhere).
What ships with it: 1 file
932 B alongside SKILL.md
- content.md932 B