mongo.code: The mongo.code class

Description Details See Also Examples

Description

Objects of class "mongo.code" are used to represent javascript code values in BSON documents.

Details

mongo.code objects' value is a string representing the value of the code.

mongo.code objects have "mongo.code" as their class so that
mongo.bson.buffer.append() may detect them and append the appropriate BSON code-typed value to a buffer.

These mongo.code values may also be present in a list and
will be handled properly by mongo.bson.buffer.append.list() and
mongo.bson.from.list().

See Also

mongo.code.create,
mongo.bson.buffer.append,
mongo.bson.buffer.append.list,
mongo.bson.buffer,
mongo.bson.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
buf <- mongo.bson.buffer.create()
code <- mongo.code.create("y = x")
mongo.bson.buffer.append(buf, "Code", code)
lst <- list(c1 = code, One = 1)
mongo.bson.buffer.append.list(buf, "listWcode", lst)
mongo.bson.buffer.append.code(buf, "Code2", "a = 1")
b <- mongo.bson.from.buffer(buf)

# the above will create a mongo.bson object of the following form:
# { "Code": (CODE) "y = x",
#   "listWcode" : { "c1"  : (CODE) "y = x",
#                   "One" : 1 },
#   "Code2" : (CODE) "a = 1" }

jonkatz2/rmongodb documentation built on May 19, 2019, 7:30 p.m.