# Here's an example. Modify it for your purposes. count <- mongo.count(mongo, ns, query) cursor <- mongo.find(mongo, query) name <- vector("character", count) age <- vector("numeric", count) i <- 1 while (mongo.cursor.next(cursor)) { b <- mongo.cursor.value(cursor) name[i] <- mongo.bson.value(b, "name") age[i] <- mongo.bson.value(b, "age") i <- i + 1 } df <- as.data.frame(list(name=name, age=age))
# rmongodb does not 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 } names <- mongo.distinct(mongo, "test", "people", "name")
mongo.bson.buffer.append.object()
mongo.bson.value()
mongo.bson.iterator.value()
mongo.bson.to.list()