mongo.aggregation: Aggregation pipeline

Description Usage Arguments Details Value See Also Examples

View source: R/mongo_high_level.R

Description

Aggregation pipeline

Usage

1
2
mongo.aggregation(mongo, ns, pipeline, explain = NULL, allowDiskUse = NULL,
  cursor = NULL, ...)

Arguments

mongo

(mongo) A mongo connection object.

ns

(string) The namespace of the collection in which to find distinct keys.

pipeline

(list of mongo.bson objects) representing aggregation query pipeline. Alternately, pipeline may be a list of list which will be converted to a mongo.bson list object by mongo.bson.from.list().

Alternately, pipeline may be a list of valid JSON character strings which will be converted to a mongo.bson object by mongo.bson.from.JSON().

explain

(logical) Optional, MongoDB 2.6+. Specifies to return the information on the processing of the pipeline. References above.

allowDiskUse

(logical) Optional, MongoDB 2.6+. Enables writing to temporary files. When set to true, aggregation stages can write data to the _tmp subdirectory in the dbPath directory.

cursor

(mongo.bson) Optional, MongoDB 2.6+. Specify a document that contains options that control the creation of the cursor object.

...

Arguments to be passed to methods, such as mongo.bson.to.list, fromJSON Unfortunately, current underlying mongo-c-driver can return BSON from aggreagation camand. Cursors are not supported.

Alternately, cursor may be a list which will be converted to a mongo.bson object by mongo.bson.from.list().

Alternately, cursor may be a valid JSON character string which will be converted to mongo.bson object by mongo.bson.from.JSON().

Details

See http://docs.mongodb.org/manual/reference/command/aggregate/ http://docs.mongodb.org/manual/core/aggregation-pipeline/.

Value

NULL if the command failed. mongo.get.err() may be MONGO_COMMAND_FAILED.

mongo.bson The result of aggregation.

See Also

mongo.command,
mongo.simple.command,
mongo.find,
mongo.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# using the zips example data set
mongo <- mongo.create()
# insert some example data
data(zips)
colnames(zips)[5] <- "orig_id"
ziplist <- list()
ziplist <- apply( zips, 1, function(x) c( ziplist, x ) )
res <- lapply( ziplist, function(x) mongo.bson.from.list(x) )
if (mongo.is.connected(mongo)) {
    mongo.insert.batch(mongo, "test.zips", res )
    pipe_1 <- mongo.bson.from.JSON('{"$group":{"_id":"$state", "totalPop":{"$sum":"$pop"}}}')
    cmd_list <- list(pipe_1)
    res <- mongo.aggregation(mongo, "test.zips", cmd_list)
}
mongo.destroy(mongo)

jonkatz2/rmongodb documentation built on May 19, 2019, 7:30 p.m.