I am trying to update date fields in mongo that require the ISODate format. In mango, it looks like this:
"crDt" : ISODate("2013-08-19T17:21:57.549Z")
I use the Java structure that I use to limit the use of strings as test parameters, so I am trying to use this string using DateTimeFormatter to get it in the correct ISODateTimeFormat and then pass this to mongo. I canβt just pass in a string similar to what I have above. Trying to do this screw the field in mongo. The corresponding bits of the Joda-Time code that I use is as follows:
And when the code runs, I get such errors from the .parseDateTime method:
java.lang.IllegalArgumentException: Invalid format: "2013-01-19T15:28:58.851Z" is malformed at "Z" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:866)
I can say that the line I am giving is incorrect in order to get into the details. I tried to get away with Z , I tried other combos, but every time he says that he is distorted. So what is my starting line to make .parseDateTime work and give me an object that looks right?
EDIT:
Updated to try the suggestions below. The problem I'm facing right now is an IllegalArgumentException, cannot serialize the org.joda.time.DateTime class. So it seems that the objects remaining in the living objects of the Jedi are missing? I also looked at another suggestion, looking at wireframes like Spring Data. It seems that there is much more that you need to delve into. Is there really no easy way to keep this in a mango?
EDIT2:
OK, I think I have it now. I might not have a full understanding of all the mechanics in the game, but BasicDBObject will not play well with DateTime . Date objects seem to be the only way, at least in the implementation I'm dealing with. I have done the following:
DateTimeFormatter parser = ISODateTimeFormat.dateTime(); DateTime result; Date newResult; result = parser.parseDateTime(crDt); newResult = result.toDate();
Then I passed newResult to the BasicDBObject object, then to update the entry in mongo. It works great and the recording is updated correctly.