buf <- mongo.bson.buffer.create()
# Append a string
mongo.bson.buffer.append(buf, "name", "Joe")
# Append a date/time
mongo.bson.buffer.append(buf, "created", Sys.time())
# Append a NULL
mongo.bson.buffer.append(buf, "cars", NULL)
b <- mongo.bson.from.buffer(buf)
iter <- mongo.bson.iterator.create(b)
while (mongo.bson.iterator.next(iter))
if (mongo.bson.iterator.type(iter) == mongo.bson.date) {
print(mongo.bson.iterator.value(iter))
break
}
# The above is given for illustrative purposes, but may be performed
# much easier by the following:
iter <- mongo.bson.find(b, "created")
print(mongo.bson.iterator.value(iter))
Run the code above in your browser using DataLab