get_mongo_collection: Retrieve data from MongoDB

View source: R/fct_helpers.R

get_mongo_collectionR Documentation

Retrieve data from MongoDB

Description

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

Usage

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

## 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/FIC documentation built on April 3, 2022, 6:05 p.m.