And this is the noSQL after running the save() method...
var object = Spark.runtimeCollection("collection").findOne(); var UTC = object["dateField"]; var newDate = new Date(UTC); object["dateField"] = newDate; Spark.runtimeCollection("collection").save(object);
Hope that helps,
-Sean
I'm seeing the same issue with the find() function, is there anyway to work with dates in gamesparks? Do I have to change everything to timestamps?
unfortunately, no, I was really hoping to be able to use the native date object in mongoDB, without having to add alot of code. I have re-factored my code to simply deal in javascript timestamps.
The problem is still there, just run this piece of cloud code
var coll = Spark.runtimeCollection("Test"); var doc = { "code" : "ALPHA", "startDate" : new Date (), } var time = doc.startDate.getTime(); coll.insert(doc); time = doc.startDate.getTime(); doc = coll.findOne({"code" : "ALPHA"}); time = doc.startDate.getTime();
the last line will fail because startDate is not a Date object
Thanks for that Christian, the team is investigating this.
Oisin
I just want to let you know that this problem is not critical on our project. We've decided to keep our date fields as number (in ms). It's probably more efficient that way anyway , no Date objects to create.
Arnold V
I'm have a runtimeCollection that has a date field stored as JS Date objects
so code like this:
Will generate an object in mongo that we can query with nice date operators, so in NoSql Explorer we can do a query like:
{"dateField":{"$lte":{"$date":"2016-08-28T15:40:42.235Z"}}} on our collection and get our row back out.
now we run this code:
We expect this to make no significant change to our data, but in this case, when we repeat our query:
{"dateField":{"$lte":{"$date":"2016-08-28T15:40:42.235Z"}}} We no longer get our row back.