Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first-class support for Date-Time values for JSON-API #362

Closed
tatu-at-datastax opened this issue Apr 17, 2023 · 3 comments
Closed

Add first-class support for Date-Time values for JSON-API #362

tatu-at-datastax opened this issue Apr 17, 2023 · 3 comments
Assignees

Comments

@tatu-at-datastax
Copy link
Contributor

tatu-at-datastax commented Apr 17, 2023

Currently we support a subset of datatypes Mongoose supports, basically matching native JSON types (Objects/sub-docs, Arrays, Number, Strings, Booleans, null), and one pseudo-type (Doc Id).

It would make sense to also support Date/Time, so users need not handle conversion to/from JSON String or Number types, but can use native Javascript Date type (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) on client-side and get it efficiently handled on JSON API server side.

Current thinking is to convention defined by EJSON (https://docs.meteor.com/api/ejson.html), in which numeric (milliseconds since 1.1.1970 timestamp, standard used by Java and Javascript as well as many other platforms) is encapsulates as a single-entry JSON Object like:

{ "$date": 1358205756553 }

This allows for reliable auto-detection because JSON API Object/sub-doc properties can not start with $ character.

Details of this approach will be added here and after/during prototyping Spec needs to be updated. We will also file separate issues for different parts of handling; so tasks include:

@vkarpov15
Copy link
Collaborator

Just a couple of details to confirm:

  1. Mongoose only has one Date type that corresponds to a Date in JavaScript and a Date in MongoDB. Mongoose doesn't have first class support for MongoDB's internal timestamp type.
  2. Mongoose does not expect timezone information to be stored with the date. Dates are 64 bit ints in MongoDB.
  3. There are no special query operators for dates. However, $eq, $in, $lt, $lte, $gt, and $gte all work on dates. In particular, myDate: { $gt: new Date() } gives you all documents where the myDate property is after right now.
  4. There is one special update operator for dates: $currentDate. That sets a property to the current date. In my experience, $currentDate is rarely used because it is easy to simply set a date to the current date.

@tatu-at-datastax
Copy link
Contributor Author

@vkarpov15 Excellent -- thank you confirming. This aligns with our understanding of things, plans (only supporting Date, not Timestamp; storage as 64-bit milliseconds since epoch; no special operators aside from $currentDate (which may be added but is not super popular)).

@tatu-at-datastax
Copy link
Contributor Author

All sub-tasks completed, Date-Time type support considered complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants