.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "MongoDB::ChangeStream 3pm" .TH MongoDB::ChangeStream 3pm "2020-08-15" "perl v5.30.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MongoDB::ChangeStream \- A stream providing update information for collections. .SH "VERSION" .IX Header "VERSION" version v2.2.2 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& $stream = $collection\->watch( $pipeline, $options ); \& while(1) { \& \& # This inner loop will only iterate until there are no more \& # changes available. \& while (my $change = $stream\->next) { \& ... \& } \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class models change stream results as returned by the \&\*(L"watch\*(R" in MongoDB::Collection method. .SH "STREAM METHODS" .IX Header "STREAM METHODS" .SS "next" .IX Subsection "next" .Vb 2 \& $change_stream = $collection\->watch(...); \& $change = $change_stream\->next; .Ve .PP Waits for the next change in the collection and returns it. .PP \&\fBNote\fR: This method will wait for the amount of milliseconds passed as \f(CW\*(C`maxAwaitTimeMS\*(C'\fR to \*(L"watch\*(R" in MongoDB::Collection or the server's default wait-time. It will not wait indefinitely. .SS "get_resume_token" .IX Subsection "get_resume_token" Users can inspect the \f(CW\*(C`_id\*(C'\fR on each \f(CW\*(C`ChangeDocument\*(C'\fR to use as a resume token. But since MongoDB 4.2, \f(CW\*(C`aggregate\*(C'\fR and \f(CW\*(C`getMore\*(C'\fR responses also include a \f(CW\*(C`postBatchResumeToken\*(C'\fR. Drivers use one or the other when automatically resuming. .PP This method retrieves the same resume token that would be used to automatically resume. Users intending to store the resume token should use this method to get the most up to date resume token. .PP For instance: .PP .Vb 3 \& if ($local_change) { \& process_change($local_change); \& } \& \& eval { \& my $change_stream = $coll\->watch([], { resumeAfter => $local_resume_token }); \& while ( my $change = $change_stream\->next) { \& $local_resume_token = $change_stream\->get_resume_token; \& $local_change = $change; \& process_change($local_change); \& } \& }; \& if (my $err = $@) { \& $log\->error($err); \& } .Ve .PP In this case the current change is always persisted locally, including the resume token, such that on restart the application can still process the change while ensuring that the change stream continues from the right logical time in the oplog. It is the application's responsibility to ensure that \f(CW\*(C`process_change\*(C'\fR is idempotent, this design merely makes a reasonable effort to process each change at least once. .SH "SEE ALSO" .IX Header "SEE ALSO" The Change Streams manual section . .PP The Change Streams specification . .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 David Golden .IP "\(bu" 4 Rassi .IP "\(bu" 4 Mike Friedman .IP "\(bu" 4 Kristina Chodorow .IP "\(bu" 4 Florian Ragwitz .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2020 by MongoDB, Inc. .PP This is free software, licensed under: .PP .Vb 1 \& The Apache License, Version 2.0, January 2004 .Ve