gerald-lindsly / rmongodb

R driver for MongoDB
http://cnub.org/rmongodb.ashx
Apache License 2.0
83 stars 44 forks source link

distinct queries #4

Closed davedkg closed 12 years ago

davedkg commented 12 years ago

Is there a way to do a distinct find all? I tried mongo.distinct() but it's not in api_mongo.h.

Thanks,

dkg

gerald-lindsly commented 12 years ago

rmongodb doesn't directly support distinct, but it can be easily implemented like so:

mongo.distinct <- function(mongo, db, collection, key) { b <- mongo.command(mongo, db, list(distinct=collection, key=key)) if (!is.null(b)) b <- mongo.bson.value(b, "values") b }

davedkg commented 12 years ago

Thank you. That worked.