Method: Mongo::Database#watch
- Defined in:
- lib/mongo/database.rb
#watch(pipeline = [], options = {}) ⇒ ChangeStream
Note:
A change stream only allows ‘majority’ read concern.
Note:
This helper method is preferable to running a raw aggregation with a $changeStream stage, for the purpose of supporting resumability.
As of version 3.6 of the MongoDB server, a “$changeStream“ pipeline stage is supported in the aggregation framework. As of version 4.0, this stage allows users to request that notifications are sent for all changes that occur in the client’s database.
526 527 528 529 530 531 532 533 534 535 |
# File 'lib/mongo/database.rb', line 526 def watch(pipeline = [], = {}) = .dup [:cursor_type] = :tailable_await if [:max_await_time_ms] Mongo::Collection::View::ChangeStream.new( Mongo::Collection::View.new(collection("#{COMMAND}.aggregate"), {}, ), pipeline, Mongo::Collection::View::ChangeStream::DATABASE, ) end |