4

I can't understand what format use ArangoDB for date storage. Attempt to insert date in such format: {"name": "vasia", "date": date("2013-01-15")}

std.json.JSONException@C:\vibe-d-0.7.24\source\vibe\data\json.d(1116): (1): Error: Expected valid JSON token, got 'date("2013-0'.

It's look like vibed JSON module fail on this string, but what format use Arango?

String in format {"name":"vasia","date":"2013-01-15"} inserting in DB successfully, but I can't understand is it's inserting as text or as Date object?

Suliman
  • 1,469
  • 3
  • 13
  • 19

2 Answers2

6

Is it inserting as text or as Date object?

As text, because ArangoDB only supports JSON data types. JSON doesn't have a Date type, so dates are usually encoded as strings. How you actually do that is up to you, but since you're using D, I suggest you use Date.toISOExtString. For a few other options, see this question.

Community
  • 1
  • 1
clinei
  • 238
  • 1
  • 7
0

I haven't used ArangoDB, but the ArangoDB date documentation suggest you use something like DATE_TIMESTAMP("2013-01-15T14:19:09.522") and / or DATE_ISO8601("2013-01-15T14:19:09.522Z"). Hope this helps.

Marten
  • 117
  • 1
  • 7
  • Both functions are AQL functions and not really necessary to insert a date. They can parse an ISO date string or number to an ISO date string in Zulu time, or to the number of milliseconds elapsed since 01.01.1970 (integer). They also have a secondary signature to create a date like so: `DATE_ISO8601(2015, 08, 16, 22, 16, 35, 234)`, see [AQL Date Functions](https://docs.arangodb.com/Aql/DateFunctions.html). To store a date, you can just do `INSERT {date: "2015-08-16T20-16-35Z"} INTO collection` with AQL, `db.collection.save({date: "2015-08-16T20-16-35Z"});` using *arangosh* etc. – CodeManX Aug 16 '15 at 20:15
  • Any ISO 8601 string will do, e.g. `new Date().toISOString()` or `Date.now()` in JavaScript. ArangoDB will actually not reject an invalid date, because it's just a string and no format is enforced from DB side. You should insert consistent dates however, or you will run into trouble when processing it later. You probably want to store all dates in Zulu time for consistency and sortability (remember, it's just a string that is being sorted). If a client supplies `2015-08-16T22:20:00+02:00` (GMT+2 timezone), just pass it through `DATE_ISO8601(...)` to convert to UTC+0 (it will also validate it). – CodeManX Aug 16 '15 at 20:21
  • @CoDEmanX do you mean something like this: ```Json str = parseJsonString(`{"name": "vasia", "date": "DATE_TIMESTAMP("2013-01-15T14:19:09.522")"}`);```? And then passing this JSON object with HTTP API (I working with it) – Suliman Aug 17 '15 at 20:42
  • No, AQL doesn't belong anywhere near JSON. Just post a payload like `{"name": "vasia", "date": "2013-01-15T14:19:09.522Z"}`. Make sure the client, which generates the date string, does so in UTC world time (note the trailing Z). If the server time is supposed to be used instead, execute an AQL query that uses `DATE_NOW()`. – CodeManX Aug 17 '15 at 21:20
  • @CoDEmanX how ArangoDB would understand is it's date or it's string, or Arango storage all date as strings? Or you mean that when Date are saving in DB every string are parsing to looking someting that may be date? – Dmitry Bubnenkov Aug 18 '15 at 08:16
  • 1
    It doesn't, there are no dates. ArangoDB is a JSON document store. You can use ISO8601 strings however. String-based sorting will return the same order as sorting date objects by date would: https://github.com/arangodb/arangodb/issues/1400 – CodeManX Aug 18 '15 at 13:28