get_mongo_collection: Retrieve data from MongoDB

Description Usage Arguments Value Examples

View source: R/fct_helpers.R

Description

Retrieve all data from a mongodb collection. Optionally, replace the collection data first.

Usage

1
get_mongo_collection(collection, db, connection_string, replace_with = NULL)

Arguments

collection

Name of the collection.

db

Name of the database the collection is in.

connection_string

Address of the mongodb server in mongo connection string [URI format](https://docs.mongodb.com/manual/reference/connection-string/).

replace_with

Default is NULL. If passed, must be a dataframe, named list (for single record) or character vector with json strings (one string for each row).

Value

Returns all data in the given collection as a dataframe.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
# Get the data in my_collection (in the my_db database)
get_mongo_collection(
  "my_collection", "my_db",
  connection_string = glue::glue(
    "mongodb+srv://{MONGO_USER}:{MONGO_PASS}@{MONGO_HOST}",
    "/?tls=true&retryWrites=true&w=majority"
  )
)

# Replace the data in my_collection (in the my_db database) with the data in
# my dataframe, then get that data
get_mongo_collection(
  "my_collection", "my_db",
  connection_string = glue::glue(
    "mongodb+srv://{MONGO_USER}:{MONGO_PASS}@{MONGO_HOST}",
    "/?tls=true&retryWrites=true&w=majority"
  ),
  replace_with = my_dataframe
)

## End(Not run)

MarkMc1089/mongo2shiny documentation built on Dec. 17, 2021, 3:13 a.m.