About
This is an implementation of the DateOnly library that works with Mongoose. This allows you to save dates in Mongo without having to worry about time zones shifting the date.
Usage
var mongoose = ;var DateOnly = mongoose; var PersonSchema = birthday: DateOnly; ... var p1 = birthday: '4/7/1995' ;var p2 = birthday: '4/7/1995' ;var p3 = birthday: '4/7/1995' ;
In Mongo, the values above would all be stored as 19950307
. Because they're not stored as conventional Date
objects, they are not subject to time zone shifts. In other words, no matter what time zone a user is in, this date will always be 4/7/1995.
The DateOnly
data type supports all of the query conditions you would expect it to:
Person;Person;Person
For full implementation details on the DateOnly
data type, please see the documentation on the DateOnly GitHub repo.
Test
npm test