Chapter 7 Server Tools
7.1 Running Commands
For mongodb operations that mongolite currently does not implement, you can still use the raw database command using the run()
method:
#> $ok
#> [1] 1
#> $cursor
#> $cursor$id
#> [1] 0
#>
#> $cursor$ns
#> [1] "test.$cmd.listCollections"
#>
#> $cursor$firstBatch
#> name type info.readOnly info.uuid idIndex.v
#> 1 flights3 collection FALSE f5, d9, 8a, 65, 8e, fc, 4f, 12, 9f, c3, fd, 8e, 24, 52, 53, a0 2
#> 2 mtcars collection FALSE 8b, c3, 77, 90, f4, fd, 41, 3e, ad, cf, 87, 50, 8c, 72, 64, b5 2
#> 3 flights collection FALSE e4, 27, 08, b2, 51, 5b, 43, 87, 8a, 05, 8e, b0, d6, 04, 42, 92 2
#> 4 issues collection FALSE 92, 5a, ff, 84, 07, b6, 46, 26, a5, 56, 91, e9, 8d, f7, 21, a4 2
#> 5 diamonds collection FALSE a0, 66, 0f, bc, c7, 46, 49, ea, a6, 1b, b8, 33, 45, d7, 81, c8 2
#> 6 flights2 collection FALSE 1a, 02, 83, 24, ce, 54, 4c, 36, 82, bd, 05, e4, 78, ee, 89, aa 2
#> 7 iris collection FALSE df, 64, d5, 0f, 9c, 70, 4a, 49, 9c, 7e, a0, 74, 57, 85, 9c, 3b 2
#> 8 subjects collection FALSE 00, 26, 2d, 7f, 85, f0, 4d, db, a4, 1f, 31, 9e, 0b, a2, b2, 64 2
#> idIndex._id idIndex.name idIndex.ns
#> 1 1 _id_ test.flights3
#> 2 1 _id_ test.mtcars
#> 3 1 _id_ test.flights
#> 4 1 _id_ test.issues
#> 5 1 _id_ test.diamonds
#> 6 1 _id_ test.flights2
#> 7 1 _id_ test.iris
#> 8 1 _id_ test.subjects
#>
#>
#> $ok
#> [1] 1
Some commands can only be run on the admin
database:
#> $databases
#> name sizeOnDisk empty
#> 1 admin 32768 FALSE
#> 2 config 73728 FALSE
#> 3 local 73728 FALSE
#> 4 test 72740864 FALSE
#>
#> $totalSize
#> [1] 72921088
#>
#> $ok
#> [1] 1
7.2 Server Info
Some server information is available in the $info()
method:
#> List of 4
#> $ collection: chr "test"
#> $ db : NULL
#> $ stats : NULL
#> $ server :List of 25
#> ..$ host : chr "Jeroens-MBP.fritz.box"
#> ..$ version : chr "4.0.1"
#> ..$ process : chr "mongod"
#> ..$ pid : num 64577
#> ..$ uptime : num 5625
#> ..$ uptimeMillis : num 5625324
#> ..$ uptimeEstimate : num 5625
#> ..$ localTime : POSIXct[1:1], format: "2018-08-09 22:18:01"
#> ..$ asserts :List of 5
#> ..$ connections :List of 3
#> ..$ extra_info :List of 2
#> ..$ freeMonitoring :List of 1
#> ..$ globalLock :List of 3
#> ..$ locks :List of 3
#> ..$ logicalSessionRecordCache:List of 11
#> ..$ network :List of 7
#> ..$ opLatencies :List of 3
#> ..$ opcounters :List of 6
#> ..$ opcountersRepl :List of 6
#> ..$ storageEngine :List of 5
#> ..$ transactions :List of 3
#> ..$ wiredTiger :List of 17
#> ..$ mem :List of 6
#> ..$ metrics :List of 10
#> ..$ ok : num 1