mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
ns <- "test.people"
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "name", "Joe")
mongo.bson.buffer.append(buf, "age", 22L)
b <- mongo.bson.from.buffer(buf)
mongo.insert(mongo, ns, b)
# do the same thing in shorthand:
mongo.insert(mongo, ns, list(name="Joe", age=22L))
}
Run the code above in your browser using DataLab