buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "scopevar", "scopevalue")
scope <- mongo.bson.from.buffer(buf)
codeWscope <- mongo.code.w.scope.create("y = x", scope)
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "CodeWscope", codeWscope)
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "CodeWscope" : (CODEWSCOPE) "y = x"
# (SCOPE) { "scopevar" : "scopevalue" } }
Run the code above in your browser using DataLab