I am using RMongo library for storing data in mongo from R. This is the script I am trying to run:
time <- "2016-12-31T23:55:43.002513Z";
mongo <- mongoDbConnect(dbName, hostName , port);
output <- dbInsertDocument(mongo, collectionName , paste0('{"Param1":', 1, ',"Param2":', 2, ',"TimeStamp":',time, '}', sep = "", collapse = ""));
Error I am getting is:
Error in .jcall(rmongo.object@javaMongo, "S", "dbInsertDocument", collection, :
com.mongodb.util.JSONParseException:
{"Param1":1,"Param2":2,"TimeStamp":2016-12-31T23:55:43.002513Z}
^
What format should I be passing the timestamp here?
Hi thanks SymbolixAU. This worked for me.
library(mongolite)
m <- mongo(collection = collectionName , db = dbName, url = hostName);
df <- data.frame(Param1 = 1, Param2 = 2, TimeStamp=as.POSIXct(time,tz="UTC"));
m$insert(df);
Just posting this for others' reference.