MongoDb recognizes the
several data types, including ISODate. I'm developing MapReduce utilities in which the expect MongoDb format output is
{ "_id" : "2012-02-10-Report", "count" : 4, "_type" : "Report", "date" : ISODate("2012-02-10T11.39.05Z"), "ts" : 1328873945000 }However,
the best I can do, so far is to produce it as follows to enclose the
ISODate type in quotes and the date in single quotes:
{
"_id" : "2012-02-10-Report", "count" : 4, "_type" : "Report", "date" :
"ISODate('2012-02-10T11.39.05Z')", "ts" : 1328873945000 }My current Mapper includes the following
SimpleDateFormat inSFM = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
SimpleDateFormat isoSFM = new SimpleDateFormat("yyyy-MM-dd'T'HH.mm.ss'Z'");BSONWritable mapOutValue = new BSONWritable();BSONWritable acmDoc = new BSONWritable();if (value.containsField(Consts.FIELD_PUBLISHED_AT)) { pubAt = value.get(Consts.FIELD_PUBLISHED_AT).toString();}try { pubDate = inSFM.parse(pubAt);
} catch (ParseException e) {...}isoSFM.setTimeZone(TimeZone.getTimeZone("UTC"));
String isoDate = "ISODate('" + isoSFM.format(pubDate).toString() + "')";mapOutValue.put("date", isoDate);...
context.write(mapOutKey, mapOutValue);Subsequent
code, is processed by a Reducer<Text, BSONWritable, Text,
BSONWritable> class. This is quite elegantly done in JavaScript. Yet,
I have not found an equivalent approach to save types in Java except
longs which convert to NumberLong("<a long number>")
Example:
mapOutValue.put("mylong", longTypeValue);Is
there a way to use the BSONWritable in and other MongoDB utilities so
and ISODate("<ISODatestring>") is the final output in a JSON
string for insert to MongoDB?
I thought I could use
mapOutValue.put("date", date);, but that just produces a date string.