Package 'mongopipe'

Title: Query MongoDB Documents with R
Description: Translate R code into MongoDB aggregation pipelines.
Authors: Oliver Haag [aut, cre]
Maintainer: Oliver Haag <[email protected]>
License: MIT + file LICENSE
Version: 0.1.1
Built: 2024-11-29 08:49:44 UTC
Source: CRAN

Help Index


Create or append a mongo aggregation stage

Description

Create or append a mongo aggregation stage

Usage

add_stage(x, ...)

## Default S3 method:
add_stage(x, ...)

## S3 method for class 'mongopipe'
add_stage(x, type, ...)

Arguments

x

Object of class mongo or mongo_pipe

...

query

type

Name of the stage.

Value

Object of type mongopipe.


Conditional expression ($cond)

Description

Evaluates a boolean expression to return one of the two specified return expressions.

Usage

condition(test, yes, no)

Arguments

test

Expression which returns a boolean value.

yes

Return this if the test returns true.

no

Return this if the test returns false.

Value

Return a list for using in mongopipe.

Examples

## Not run: 
cond <- condition(test = list("$isArray"="$chart"),
                  yes = list("$size"="$chart"),
                  no = 0)
jsonlite::toJSON(cond)

## End(Not run)

Pipeline Stages

Description

These functions translate R code to json readably by Mongodb.

Usage

match(x, ...)

## S3 method for class 'mongopipe'
match(x, ...)

field(x, ...)

## S3 method for class 'mongopipe'
field(x, ...)

lookup(x, ...)

## S3 method for class 'mongopipe'
lookup(x, from, local_field = from, foreign_field = "_id", as = from, ...)

unwind(x, ...)

## S3 method for class 'mongopipe'
unwind(x, field, ...)

limit(x, ...)

## S3 method for class 'mongopipe'
limit(x, limit, ...)

project(x, ...)

## S3 method for class 'mongopipe'
project(x, ...)

Arguments

x

Object of class mongopipe

...

list object

from

Collection to join

local_field

Field from the input documents

foreign_field

Field from the documents of the "from" collection

as

Name of output array field (Default: from)

field

Field to unwind.

limit

Integer to limit the number of documents.

Value

Object of type mongopipe.


Mongopipe

Description

Mongopipe

Usage

mongopipe()

Value

Object of type mongopipe.