dbAggregate-methods: Performing a MongoDB aggregate query

Description Usage Arguments See Also Examples

Description

Send a set of aggregate pipeline commands to mongodb. The output is a data.frame object and will work properly only if the mongoDB collection contains primitive data types. It may not work properly if there are any embedded documents or arrays.

Usage

1
  dbAggregate(rmongo.object, collection, query) 

Arguments

rmongo.object

The RMongo object.

collection

The name of the collection the query is being performed upon.

query

A vector of pipeline command in JSON format. See http://docs.mongodb.org/manual/reference/aggregation/ for more information on the MongoDB aggregation framework.

See Also

mongoDbConnect

Examples

1
2
3
4
5
6
7
8
  mongo <- mongoDbConnect("test")
  # insert two records
  dbInsertDocument(mongo, "test_data", '{"foo": "bar", "size": 5 }')
  dbInsertDocument(mongo, "test_data", '{"foo": "nl", "size": 10 }')
  output <- dbAggregate(mongo, "test_data", c(' { "$project" : { "baz" : "$foo" } } ',
                                              ' { "$group" : { "_id" : "$baz" } } ',
                                              ' { "$match" : { "_id" : "bar" } } '))
  print(output)

RMongo documentation built on May 30, 2017, 2:31 a.m.