mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
# alternate method of renaming a collection
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "renameCollection", "test.people")
mongo.bson.buffer.append(buf, "to", "test.humans")
command <- mongo.bson.from.buffer(buf)
mongo.command(mongo, "admin", command)
# use list notation to rename the collection back
mongo.command(mongo, "admin",
list(renameCollection="test.humans", to="test.people"))
# Alternate method of counting people
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "count", "people")
mongo.bson.buffer.append(buf, "query", mongo.bson.empty())
command <- mongo.bson.from.buffer(buf)
result = mongo.command(mongo, "test", command)
if (!is.null(result)) {
iter = mongo.bson.find(result, "n")
print(mongo.bson.iterator.value(iter))
}
}
Run the code above in your browser using DataLab