Question

I fetch the data from ScriptDb in this way:

var db = ScriptDb.getMyDb();
var result = db.query({}).sortBy('timestamp', db.DESCENDING);
while (result.hasNext()) {
  Logger.log(result.next());
}

The data are saved in this way:

var item = {
  ...,
  timestamp: someDate.getTime()
};
db.save(item);

The result returned from the sorted query is correct for all the values apart from the top one:

timestamp=1.3995E12 <-- top value wrong (7th May)

timestamp=1.39956822E12 <-- second value correct (8th May)

timestamp=1.399374991E12 <-- third value correct (6th May)

....follow other correctly sorted values

Why the first value is wrong? Am I doing something wrong?

Was it helpful?

Solution

Well, I solved changing the line:

timestamp: someDate.getTime()

in

timestamp: someDate.getTime().toString()

that save the timestamps as string, from the form 1.399374991E12 to 1399374991000 and finally sorting correctly. Weird, it looks a bug in ScriptDb.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top