Class: BSON::DBRef

Inherits:
Object
  • 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

#initialize(namespace, object_id) ⇒ DBRef

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

Parameters:

  • a (String)

    collection name

  • an (ObjectId)

    object id


28
29
30
31
# File 'lib/bson/types/dbref.rb', line 28

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

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace


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

def namespace
  @namespace
end

#object_idObject (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

#to_hashObject


37
38
39
# File 'lib/bson/types/dbref.rb', line 37

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

#to_sObject


33
34
35
# File 'lib/bson/types/dbref.rb', line 33

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