{"success":true,"name":"store-dates-in-mongodb-as-date-type-never-as-strings","description":"Saving or querying date/time values in MongoDB documents","category":"ai-brimind","path":"ai-brimind/store-dates-in-mongodb-as-date-type-never-as-strings/SKILL.md","file":"SKILL.md","content":"---\nname: store-dates-in-mongodb-as-date-type-never-as-strings\ndescription: \"Saving or querying date/time values in MongoDB documents\"\n---\n\n# Store Dates in MongoDB as Date Type, Never as Strings\n\n## When to use\nProject uses MongoDB, and a field holds a date, timestamp, or time value being written or filtered.\n\n## Example request\nSaving '07/06/2026' as a string → range queries and sorting break; '10/01' sorts before '09/30' as text. TTL index never deletes anything → TTL only works on real Date values; strings are silently ignored. Comparing dates saved in mixed formats → some ISO, some locale strings; nothing matches reliably. Timezone bugs in reports → Date stores UTC milliseconds; format at display time, not at storage time. Each maps to 'a date stored as text loses ordering, math, and every date feature'.\n\n## Instructions\nAct as a developer who treats a date stored as a string in MongoDB as a bug waiting to be found. For every date-like field: (1) store a real BSON Date (new Date(), Mongoose type Date) — never a formatted string, because Date gives correct sorting, $gte/$lte range queries, TTL support, and date aggregation operators ($dateToString, $dateTrunc) for free, (2) keep storage in UTC and do timezone formatting only at the display boundary, naming the concept: store canonical, format at the edge, (3) when input arrives as a string (forms, APIs, CSV), parse and validate it at the boundary before saving — reject unparseable values instead of storing them as-is, (4) if you find existing string dates in a collection, treat that as a data problem: plan a conversion migration rather than writing string-comparison workarounds in queries. If the required precision or timezone rule is unclear, ask. Only save the field once it is a confirmed Date type, and explain why every date feature of the database now works instead of silently failing.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1141\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}