Class: Mongo::DBRef
Overview
Represents a DBRef document in the database.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- COLLECTION =
The constant for the collection reference field.
'$ref'.freeze
- ID =
The constant for the id field.
'$id'.freeze
- DATABASE =
The constant for the database field.
'$db'.freeze
Instance Attribute Summary collapse
-
#collection ⇒ String
readonly
Collection The collection name.
-
#database ⇒ String
readonly
Database The database name.
-
#id ⇒ BSON::ObjectId
readonly
Id The referenced document id.
Instance Method Summary collapse
-
#as_json(*args) ⇒ Hash
Get the DBRef as a JSON document.
-
#initialize(collection, id, database = nil) ⇒ DBRef
constructor
Instantiate a new DBRef.
-
#to_bson(buffer = BSON::ByteBuffer.new) ⇒ String
Converts the DBRef to raw BSON.
Constructor Details
#initialize(collection, id, database = nil) ⇒ DBRef
Instantiate a new DBRef.
71 72 73 74 75 |
# File 'lib/mongo/dbref.rb', line 71 def initialize(collection, id, database = nil) @collection = collection @id = id @database = database end |
Instance Attribute Details
#collection ⇒ String (readonly)
Returns collection The collection name.
39 40 41 |
# File 'lib/mongo/dbref.rb', line 39 def collection @collection end |
#database ⇒ String (readonly)
Returns database The database name.
45 46 47 |
# File 'lib/mongo/dbref.rb', line 45 def database @database end |
#id ⇒ BSON::ObjectId (readonly)
Returns id The referenced document id.
42 43 44 |
# File 'lib/mongo/dbref.rb', line 42 def id @id end |
Instance Method Details
#as_json(*args) ⇒ Hash
Get the DBRef as a JSON document
55 56 57 58 59 |
# File 'lib/mongo/dbref.rb', line 55 def as_json(*args) document = { COLLECTION => collection, ID => id } document.merge!(DATABASE => database) if database document end |
#to_bson(buffer = BSON::ByteBuffer.new) ⇒ String
Converts the DBRef to raw BSON.
87 88 89 |
# File 'lib/mongo/dbref.rb', line 87 def to_bson(buffer = BSON::ByteBuffer.new) as_json.to_bson(buffer) end |