Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.find: Find a field within a mongo.bson object by name

Description

Find a field within a mongo.bson object by the name (key) of the field and return a mongo.bson.iterator pointing to that field.

Usage

mongo.bson.find(b, name)

Arguments

b
(mongo.bson) The object in which to find the field.
name
(string) The name of the field to find.

Value

(mongo.bson.iterator) An iterator pointing to the field found if name was found among the names of the fields; otherwise, NULL.

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, mongo.bson.iterator.value, mongo.bson.

Examples

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

iter <- mongo.bson.find(b, "address.city")
print(mongo.bson.iterator.value(iter)) # print Denver

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

Run the code above in your browser using DataLab