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