Search code examples
rmongodbmongodb-queryrmongodbrmongo

Get data statistics in R with rmongodb or RMongo


Using robomongo I can get basic description of the data using

db.getCollection('Exempt').stats()

but i cannot seem to get this info in nR using the rmongodb or RMongo packages.

Can anyone please help?

Regards, Abhishek


Solution

  • You can get this information (and more) using library(mongolite). The command you want is mongo$info()

    library(mongolite)
    
    mongo <- mongo(collection = "test", db = "test")
    info <- mongo$info()
    info$stats
    
    # $ns
    # [1] "test.test"
    # 
    # $count
    # [1] 0
    # 
    # $size
    # [1] 0
    # 
    # $storageSize
    # [1] 8192
    # 
    # $numExtents
    # [1] 1
    # 
    # $nindexes
    # [1] 1
    # 
    # $lastExtentSize
    # [1] 8192
    # 
    # $paddingFactor
    # [1] 1
    # 
    # $systemFlags
    # [1] 1
    # 
    # $userFlags
    # [1] 1
    # 
    # $totalIndexSize
    # [1] 8176
    # 
    # $indexSizes
    # $indexSizes$`_id_`
    # [1] 8176
    # 
    # 
    # $ok
    # [1] 1
    
    rm(mongo); gc()