class Mongo::Database
- Mongo::Database
- Reference
- Object
Overview
A Database
provides access to a MongoDB database.
database = client["database_name"]
Included Modules
- Mongo::WithReadConcern
- Mongo::WithReadPreference
- Mongo::WithWriteConcern
Defined in:
cryomongo/database.crInstance Method Summary
-
#[](collection : Collection::CollectionKey) : Mongo::Collection
Get a newly allocated
Mongo::Collection
for the collection named name. -
#aggregate(pipeline : Array, *, allow_disk_use : Bool? = nil, batch_size : Int32? = nil, max_time_ms : Int64? = nil, bypass_document_validation : Bool? = nil, read_concern : ReadConcern? = nil, collation : Collation? = nil, hint : String | H? = nil, comment : String? = nil, write_concern : WriteConcern? = nil, session : Session::ClientSession? = nil) : Mongo::Cursor? forall H
Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.
-
#client : Mongo::Client
The underlying MongoDB client.
-
#collection(collection : Collection::CollectionKey) : Mongo::Collection
Get a newly allocated
Mongo::Collection
for the collection named name. -
#command(operation, write_concern : WriteConcern? = nil, read_concern : ReadConcern? = nil, read_preference : ReadPreference? = nil, session : Session::ClientSession? = nil, **args, &)
Execute a command on the server targeting the database.
-
#command(operation, write_concern : WriteConcern? = nil, read_concern : ReadConcern? = nil, read_preference : ReadPreference? = nil, session : Session::ClientSession? = nil, **args)
Execute a command on the server targeting the database.
-
#grid_fs(bucket_name : String = "fs", *, chunk_size_bytes : Int32 = 255 * 1024, write_concern : WriteConcern? = nil, read_concern : ReadConcern? = nil, read_preference : ReadPreference? = nil) : GridFS::Bucket
Returns a
Mongo::GridFS
instance configured with the arguments provided. -
#list_collections(*, filter = nil, name_only : Bool? = nil, authorized_collections : Bool? = nil, session : Session::ClientSession? = nil) : Mongo::Cursor
Retrieve information, i.e.
-
#name : String
The database name.
-
#read_concern : ReadConcern?
Read concern accessor.
-
#read_concern=(read_concern : ReadConcern?)
Read concern accessor.
-
#read_preference : ReadPreference?
ReadPreference accessor.
-
#read_preference=(read_preference : ReadPreference?)
ReadPreference accessor.
-
#stats(*, scale : Int32? = nil) : BSON?
Returns a variety of storage statistics for the database.
-
#watch(pipeline : Array = [] of BSON, *, full_document : String? = nil, resume_after : BSON? = nil, max_await_time_ms : Int64? = nil, batch_size : Int32? = nil, collation : Collation? = nil, start_at_operation_time : Time? = nil, start_after : BSON? = nil, read_concern : ReadConcern? = nil, read_preference : ReadPreference? = nil, session : Session::ClientSession? = nil) : Mongo::ChangeStream::Cursor
Returns a
ChangeStream::Cursor
watching all the database collection. -
#write_concern : WriteConcern?
Write concern accessor.
-
#write_concern=(write_concern : WriteConcern?)
Write concern accessor.
Instance Method Detail
Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.
NOTE for more details, please check the official MongoDB documentation.
Execute a command on the server targeting the database.
Will automatically set the database arguments.
Execute a command on the server targeting the database.
Will automatically set the database arguments.
Returns a Mongo::GridFS
instance configured with the arguments provided.
NOTE for more details about GridFS, please check the official MongoDB manual.
Retrieve information, i.e. the name and options, about the collections and views in a database.
Specifically, the command returns a document that contains information with which to create a cursor to the collection information.
NOTE for more details, please check the official MongoDB documentation.
Returns a variety of storage statistics for the database.
NOTE for more details, please check the official MongoDB documentation.
Returns a ChangeStream::Cursor
watching all the database collection.
NOTE Excludes system collections.
client = Mongo::Client.new
database = client["db"]
spawn {
cursor = database.watch(
[
{"$match": {"operationType": "insert"}},
],
max_await_time_ms: 10000
)
# cursor.of(BSON) converts to the Mongo::ChangeStream::Document(BSON) type.
cursor.of(BSON).each { |doc|
puts doc.to_bson.to_json
}
}
100.times do |i|
database["collection"].insert_one({count: i})
end
sleep