Method: BSON::Code#initialize

Defined in:
lib/jmongo/mongo/bson.rb

#initialize(code, scope = {}) ⇒ Code

Wrap code to be evaluated by MongoDB.

Parameters:

  • code (String)

    the JavaScript code.

  • a (Hash)

    document mapping identifiers to values, which represent the scope in which the code is to be executed.



69
70
71
72
73
74
# File 'lib/jmongo/mongo/bson.rb', line 69

def initialize(code, scope={})
  unless code.is_a?(String)
    raise ArgumentError, "BSON::Code must be in the form of a String; #{code.class} is not accepted."
  end
  @bson_code  = BsonCode.new(code, scope.to_bson)
end