abstract class Moongoon::Document

Overview

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

Included Modules

Defined in:

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(pull : JSON::PullParser) #

def self.new(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)

def self.new(**args : **T) forall T #

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 Method Detail

def self.from_bson(bson : BSON) #

NOTE See self.new.


Instance Method Detail

def to_bson(bson = BSON.new) #

Converts to a BSON representation.

user = User.new name: "John"
bson = user.to_bson

def 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.