Learn R Programming

RMongo (version 0.0.25)

dbAggregate-methods: Performing a MongoDB aggregate query

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

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

Run this code
  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)

Run the code above in your browser using DataLab