Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R MongoDB-ISODate_R_Mongodb - Fatal编程技术网

R MongoDB-ISODate

R MongoDB-ISODate,r,mongodb,R,Mongodb,我正在编写一个RScript来比较当前系统时间戳和MongoDB上次更新的时间戳。 我的做法: db.runs.find() ObjectId(“5b27f3957cf77b51d60c1502”).getTimeStamp()-输出:ISODate(“2018-06-18T18:01:57Z”) 这些步骤是否可以在R中编写脚本,以便我可以将此ISODate与当前系统时间戳进行比较?或者有没有其他方法来达到这一要求 此功能对我有效: library(base) get_date_from_ob

我正在编写一个RScript来比较当前系统时间戳和MongoDB上次更新的时间戳。 我的做法:

  • db.runs.find()
  • ObjectId(“5b27f3957cf77b51d60c1502”).getTimeStamp()
    -输出:ISODate(“2018-06-18T18:01:57Z”)

  • 这些步骤是否可以在R中编写脚本,以便我可以将此ISODate与当前系统时间戳进行比较?或者有没有其他方法来达到这一要求

    此功能对我有效:

    library(base)
    
    get_date_from_objectid <- function(oid) {
      #Get first 8 Hexa characters from ObjectId corresponding with the datetime:
      datetime_Hex <- paste("0x", substr(oid, 0, 8), sep = "")
    
      #Convert from Hexa to Decimal using base::strtoi():
      datetime_Decimal <- strtoi(c(datetime_Hex))
    
      #Get the date from de the decimal value:
      date = as.Date.POSIXct(datetime_Decimal, origin="1970-01-01")
      return(date)
    }
    
    
    #Example
    objectId= "5dfce6ad859e645780f88b53"
    get_date_from_objectid(objectId)
    
    #This will return "2019-12-20"
    
    库(基本)
    get_date_from_objectid注意:在开头添加了“0x”以将代码解释为十六进制