Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.buffer.append.code.w.scope: Append a code field with a scope onto a mongo.bson.buffer

Description

Append a javascript code value with a scope object onto a mongo.bson.buffer.

Usage

mongo.bson.buffer.append.code.w.scope(buf, name, value)

Arguments

buf
(mongo.bson.buffer) The buffer object to which to append.
name
(string) The name (key) of the field appended to the buffer.
value
mongo.code.w.scope The scoped javascript code.

Value

TRUE if successful; otherwise, FALSE if an error occured appending the data.

Details

BSON has a special field type to indicate javascript code with a scope. This function appends such an indicator as the type of a field with its value.

See Also

mongo.code.w.scope, mongo.code.w.scope.create, mongo.bson.buffer.append, mongo.bson.from.list, mongo.bson.buffer, mongo.bson.

Examples

Run this code
scope <- mongo.bson.from.list(list(scopevar="scopevalue"))
buf <- mongo.bson.buffer.create()
codeWscope <- mongo.code.w.scope.create("y = x", scope)
mongo.bson.buffer.append.code.w.scope(buf, "CodeWscope1",
     codeWscope)

# mongo.bson.buffer.append() will give the same result
# as it can detect the mongo.code.w.scope object
mongo.bson.buffer.append(buf, "CodeWscope2", codeWscope)

b <- mongo.bson.from.buffer(buf)

# The above produces a BSON object of the form:
# { "CodeWscope1" : (CODEWSCOPE) "y = x"
#        (SCOPE) { "scopevar" : "scopevalue" },
#   "CodeWscope2" : (CODEWSCOPE) "y = x"
#        (SCOPE) { "scopevar" : "scopevalue" } }

Run the code above in your browser using DataLab