Description Usage Arguments Details Value See Also Examples
Search a mongo.bson object for a field by name and retrieve its value.
1 | mongo.bson.value(b, name)
|
b |
A mongo.bson object. |
name |
(string) The name of a field within |
The search parameter may also be a 'dotted' reference to a field in a subobject or array. See examples.
NULL if name is not found;
otherwise, the value of the found
field.
This function returns an appropriate R object depending on the type of the field found. This mapping to values is as follows:
mongo.bson.double | A double |
mongo.bson.string | A string |
mongo.bson.object | (See below). |
mongo.bson.array | (See below). |
mongo.bson.binary | A raw object. (See below). |
mongo.bson.undefined | A mongo.undefined object |
mongo.bson.oid | A mongo.oid object |
mongo.bson.bool | A logical |
mongo.bson.date | A "POSIXct" class object |
mongo.bson.null | NULL |
mongo.bson.regex
| A mongo.regex object |
mongo.bson.dbref | Error! (deprecated -- see link) |
mongo.bson.code | A mongo.code object |
mongo.bson.symbol | A mongo.symbol object |
mongo.bson.code.w.scope | A mongo.code.w.scope object |
mongo.bson.int | An integer |
mongo.bson.timestamp | A mongo.timestamp object |
mongo.bson.long | A double |
Special handling:
mongo.bson.object
: If the object is recognized as a complex
value (of the form "r" : double, "i" : double ), a complex value is
returned. If the special wrapper as output by
mongo.bson.buffer.append.object()
is detected, an
appropriately attributed R object is returned; otherwise, a list is returned
containing the subfields.
mongo.bson.array
: If all fields of the array are of the same
atomic type, a vector of that type is returned. (Multidimensinal arrays are
detected and the dims
attribute will be set accordingly. Arrays of
complex values are also detected as above). Otherwise, a list is returned
containing the subfields.
mongo.bson.binary
: If non-zero, the subtype of the binary data
is stored in the attribute "subtype". See
mongo.bson.buffer.append.raw()
.
mongo.bson.iterator.value,
mongo.bson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.