1MongoDB::ChangeStream(3U)ser Contributed Perl DocumentatiMoonngoDB::ChangeStream(3)
2
3
4

NAME

6       MongoDB::ChangeStream - A stream providing update information for
7       collections.
8

VERSION

10       version v2.2.1
11

SYNOPSIS

13           $stream = $collection->watch( $pipeline, $options );
14           while(1) {
15
16               # This inner loop will only iterate until there are no more
17               # changes available.
18               while (my $change = $stream->next) {
19                   ...
20               }
21           }
22

DESCRIPTION

24       This class models change stream results as returned by the "watch" in
25       MongoDB::Collection method.
26

STREAM METHODS

28   next
29           $change_stream = $collection->watch(...);
30           $change = $change_stream->next;
31
32       Waits for the next change in the collection and returns it.
33
34       Note: This method will wait for the amount of milliseconds passed as
35       "maxAwaitTimeMS" to "watch" in MongoDB::Collection or the server's
36       default wait-time. It will not wait indefinitely.
37
38   get_resume_token
39       Users can inspect the "_id" on each "ChangeDocument" to use as a resume
40       token. But since MongoDB 4.2, "aggregate" and "getMore" responses also
41       include a "postBatchResumeToken". Drivers use one or the other when
42       automatically resuming.
43
44       This method retrieves the same resume token that would be used to
45       automatically resume. Users intending to store the resume token should
46       use this method to get the most up to date resume token.
47
48       For instance:
49
50           if ($local_change) {
51               process_change($local_change);
52           }
53
54           eval {
55               my $change_stream = $coll->watch([], { resumeAfter => $local_resume_token });
56               while ( my $change = $change_stream->next) {
57                   $local_resume_token = $change_stream->get_resume_token;
58                   $local_change = $change;
59                   process_change($local_change);
60               }
61           };
62           if (my $err = $@) {
63               $log->error($err);
64           }
65
66       In this case the current change is always persisted locally, including
67       the resume token, such that on restart the application can still
68       process the change while ensuring that the change stream continues from
69       the right logical time in the oplog. It is the application's
70       responsibility to ensure that "process_change" is idempotent, this
71       design merely makes a reasonable effort to process each change at least
72       once.
73

SEE ALSO

75       The Change Streams manual section
76       <https://docs.mongodb.com/manual/changeStreams/>.
77
78       The Change Streams specification
79       <https://github.com/mongodb/specifications/blob/master/source/change-
80       streams.rst>.
81

AUTHORS

83       ·   David Golden <david@mongodb.com>
84
85       ·   Rassi <rassi@mongodb.com>
86
87       ·   Mike Friedman <friedo@friedo.com>
88
89       ·   Kristina Chodorow <k.chodorow@gmail.com>
90
91       ·   Florian Ragwitz <rafl@debian.org>
92
94       This software is Copyright (c) 2019 by MongoDB, Inc.
95
96       This is free software, licensed under:
97
98         The Apache License, Version 2.0, January 2004
99
100
101
102perl v5.30.1                      2020-01-30          MongoDB::ChangeStream(3)
Impressum