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