Class: Mongo::DBRef
- Inherits:
-
Object
- Object
- Mongo::DBRef
- Includes:
- BSON::JSON
- Defined in:
- build/ruby-driver-v2.17/lib/mongo/dbref.rb
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, validating_keys = BSON::Config.validating_keys?) ⇒ String
Converts the DBRef to raw BSON.
Constructor Details
#initialize(collection, id, database = nil) ⇒ DBRef
Instantiate a new DBRef.
74 75 76 77 78 |
# File 'build/ruby-driver-v2.17/lib/mongo/dbref.rb', line 74 def initialize(collection, id, database = nil) @collection = collection @id = id @database = database end |
Instance Attribute Details
#collection ⇒ String (readonly)
Returns collection The collection name.
42 43 44 |
# File 'build/ruby-driver-v2.17/lib/mongo/dbref.rb', line 42 def collection @collection end |
#database ⇒ String (readonly)
Returns database The database name.
48 49 50 |
# File 'build/ruby-driver-v2.17/lib/mongo/dbref.rb', line 48 def database @database end |
#id ⇒ BSON::ObjectId (readonly)
Returns id The referenced document id.
45 46 47 |
# File 'build/ruby-driver-v2.17/lib/mongo/dbref.rb', line 45 def id @id end |
Instance Method Details
#as_json(*args) ⇒ Hash
Get the DBRef as a JSON document
58 59 60 61 62 |
# File 'build/ruby-driver-v2.17/lib/mongo/dbref.rb', line 58 def as_json(*args) document = { COLLECTION => collection, ID => id } document.merge!(DATABASE => database) if database document end |
#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = BSON::Config.validating_keys?) ⇒ String
Converts the DBRef to raw BSON.
91 92 93 |
# File 'build/ruby-driver-v2.17/lib/mongo/dbref.rb', line 91 def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = BSON::Config.validating_keys?) as_json.to_bson(buffer) end |