Moongoon::Document
Inherits BSON::Serializable / JSON::Serializable / Reference / Object
Base model class.
Contains helpers to (de)serialize data to json format and bson format.
class Models::MyModel < Moongoon::Document
property name : String
property age : Int32
end
Constructors
new(pull : JSON::PullParser)
Sourcenew(bson : BSON)
Allocate an instance and copies data from a BSON struct.
class User
include BSON::Serializable
property name : String
end
data = BSON.new
data["name"] = "John"
User.new(data)
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Sourcenew
Creates a new instance of the class from variadic arguments.
User.new first_name: "John", last_name: "Doe"
NOTE: Only instance variables having associated setter methods will be initialized.
Class methods
Instance methods
to_bson(bson = BSON.new)
Converts to a BSON representation.
user = User.new name: "John"
bson = user.to_bson
to_tuple
Instantiate a named tuple from the model instance properties.
user = User.new first_name: "John", last_name: "Doe"
pp user.to_tuple
# => {
# first_name: "John",
# last_name: "Doe",
# }
NOTE: Only instance variables having associated getter methods will be returned.