jeroen / mongolite

Fast and Simple MongoDB Client for R

Home Page:https://jeroen.github.io/mongolite/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting the URI and DB name from a mongo object

grimmjulian opened this issue · comments

Hello,

I was wondering, if there is a good way to get the URI and the DB name from a mongo object?

For the DB name, I tried m$info()$db, which returns only NULL. I then used strsplit(x$info()$stats$ns, "\\.")[[1]][[1]], but I feel there should be a better solution?
For URI, I did not find anything.

Thanks in advance!

I found the following solution for my problem:

m <- mongolite::mongo()

get_orig_content <- function(name) {
  function(m) {
    parent.env(m)[["orig"]][[name]]
  }
}

name <- get_orig_content("name") # this is the collection
db <- get_orig_content("db")
url <- get_orig_content("url")

name(m)
db(m)
url(m)