Class: BSON::DBRef

Inherits:
Object show all
Defined in:
lib/bson/types/dbref.rb

Overview

A reference to another object in a MongoDB database.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (DBRef) initialize(namespace, object_id)

Create a DBRef. Use this class in conjunction with DB#dereference.

Parameters:

  • namespace (String)

    a collection name.

  • object_id (ObjectId)

    an object id.



26
27
28
29
# File 'lib/bson/types/dbref.rb', line 26

def initialize(namespace, object_id)
  @namespace = namespace
  @object_id = object_id
end

Instance Attribute Details

- (Object) namespace (readonly)

Returns the value of attribute namespace



20
21
22
# File 'lib/bson/types/dbref.rb', line 20

def namespace
  @namespace
end

- (Object) object_id (readonly)

Returns the value of attribute object_id



20
21
22
# File 'lib/bson/types/dbref.rb', line 20

def object_id
  @object_id
end

Instance Method Details

- (Object) to_hash



35
36
37
# File 'lib/bson/types/dbref.rb', line 35

def to_hash
  {"$ns" => @namespace, "$id" => @object_id }
end

- (Object) to_s



31
32
33
# File 'lib/bson/types/dbref.rb', line 31

def to_s
  "ns: #{namespace}, id: #{object_id}"
end