Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
MongoDB::ChangeStream(User Contributed Perl DocumentatMongoDB::ChangeStream(3)

NAME
       MongoDB::ChangeStream - A stream	providing update information for
       collections.

VERSION
       version v2.2.2

SYNOPSIS
	   $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) {
		   ...
	       }
	   }

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

STREAM METHODS
   next
	   $change_stream = $collection->watch(...);
	   $change = $change_stream->next;

       Waits for the next change in the	collection and returns it.

       Note: This method will wait for the amount of milliseconds passed as
       "maxAwaitTimeMS"	to "watch" in MongoDB::Collection or the server's
       default wait-time. It will not wait indefinitely.

   get_resume_token
       Users can inspect the "_id" on each "ChangeDocument" to use as a	resume
       token. But since	MongoDB	4.2, "aggregate" and "getMore" responses also
       include a "postBatchResumeToken". Drivers use one or the	other when
       automatically resuming.

       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.

       For instance:

	   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);
	   }

       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 "process_change" is idempotent, this
       design merely makes a reasonable	effort to process each change at least
       once.

SEE ALSO
       The Change Streams manual section
       <https://docs.mongodb.com/manual/changeStreams/>.

       The Change Streams specification
       <https://github.com/mongodb/specifications/blob/master/source/change-
       streams.rst>.

AUTHORS
       o   David Golden	<david@mongodb.com>

       o   Rassi <rassi@mongodb.com>

       o   Mike	Friedman <friedo@friedo.com>

       o   Kristina Chodorow <k.chodorow@gmail.com>

       o   Florian Ragwitz <rafl@debian.org>

COPYRIGHT AND LICENSE
       This software is	Copyright (c) 2020 by MongoDB, Inc.

       This is free software, licensed under:

	 The Apache License, Version 2.0, January 2004

perl v5.32.0			  2020-08-13	      MongoDB::ChangeStream(3)

NAME | VERSION | SYNOPSIS | DESCRIPTION | STREAM METHODS | SEE ALSO | AUTHORS | COPYRIGHT AND LICENSE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=MongoDB::ChangeStream&sektion=3&manpath=FreeBSD+12.1-RELEASE+and+Ports>

home | help