Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

37 lines (31 sloc) 1.361 kb
\title{Performing a MongoDB aggregate query}
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.
dbAggregate(rmongo.object, collection, query)
\item{rmongo.object}{The RMongo object.}
\item{collection}{The name of the collection the query is being performed upon.}
\item{query}{A vector of pipeline command in JSON format. See for more information on the MongoDB aggregation framework.}
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" } } '))
Jump to Line
Something went wrong with that request. Please try again.