Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.value: Return the value of a mongo.bson field

Description

Search a mongo.bson object for a field by name and retrieve its value.

Usage

mongo.bson.value(b, name)

Arguments

b
A mongo.bson object.
name
(string) The name of a field within b.

Value

Details

The search parameter may also be a 'dotted' reference to a field in a subobject or array. See examples.

See Also

mongo.bson.iterator.value, mongo.bson.

Examples

Run this code
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)

# Display the date appended above
print(mongo.bson.value(b, "created"))

b <- mongo.bson.from.list(list(name="John", age=32L,
     address=list(street="Vine", city="Denver", state="CO")))
print(mongo.bson.value(b, "age")) # print 32
print(mongo.bson.value(b, "address.state")) # print CO

x <- c(1,1,2,3,5)
b <- mongo.bson.from.list(list(fib=x)) # BSON arrays are 0-based
print(mongo.bson.value(b, "fib.4")) # print 5

Run the code above in your browser using DataLab