Method: Mongo::Client#watch
- Defined in:
- lib/mongo/client.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 cluster.
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 |
# File 'lib/mongo/client.rb', line 1112 def watch(pipeline = [], = {}) return use(Database::ADMIN).watch(pipeline, ) unless database.name == Database::ADMIN = .dup [:cursor_type] = :tailable_await if [:max_await_time_ms] Mongo::Collection::View::ChangeStream.new( Mongo::Collection::View.new(self["#{Database::COMMAND}.aggregate"], {}, ), pipeline, Mongo::Collection::View::ChangeStream::CLUSTER, ) end |