Mongo::Database
Inherits Mongo::WithReadPreference / Mongo::WithWriteConcern / Mongo::WithReadConcern / Reference / Object
A Database provides access to a MongoDB database.
database = client["database_name"]
Instance methods
Get a newly allocated Mongo::Collection for the collection named name.
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.
Get a newly allocated Mongo::Collection for the collection named name.
Execute a command on the server targeting the database.
Will automatically set the database arguments.
See: Mongo::Client.command
Execute a command on the server targeting the database.
Will automatically set the database arguments.
See: Mongo::Client.command
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.
Read concern accessor.
Read concern accessor.
ReadPreference accessor.
ReadPreference accessor.
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
Write concern accessor.
Write concern accessor.