1MongoDB::QueryResult(3)User Contributed Perl DocumentatioMnongoDB::QueryResult(3)
2
3
4

NAME

6       MongoDB::QueryResult - An iterator for Mongo query results
7

VERSION

9       version v2.0.3
10

SYNOPSIS

12           $cursor = $coll->find( $filter );
13           $result = $cursor->result;
14
15           while ( $doc = $result->next ) {
16               process_doc($doc)
17           }
18

DESCRIPTION

20       This class defines an iterator against a query result.  It
21       automatically fetches additional results from the originating
22       mongod/mongos server on demand.
23
24       For backwards compatibility reasons, MongoDB::Cursor encapsulates query
25       parameters and generates a "MongoDB::QueryResult" object on demand.
26       All iterators on "MongoDB::Cursor" delegate to "MongoDB::QueryResult"
27       object.
28
29       Retrieving this object and iterating on it directly will be slightly
30       more efficient.
31

USAGE

33   Error handling
34       Unless otherwise explicitly documented, all methods throw exceptions if
35       an error occurs.  The error types are documented in MongoDB::Error.
36
37       To catch and handle errors, the Try::Tiny and Safe::Isa modules are
38       recommended:
39
40   Cursor destruction
41       When a "MongoDB::QueryResult" object is destroyed, a cursor termination
42       request will be sent to the originating server to free server
43       resources.
44
45   Multithreading
46       Iterators are cloned in threads, but not reset.  Iterating from
47       multiple threads will give unpredictable results.  Only iterate from a
48       single thread.
49

METHODS

51   has_next
52           if ( $response->has_next ) {
53               ...
54           }
55
56       Returns true if additional documents are available.  This will attempt
57       to get another batch of documents from the server if necessary.
58
59   next
60           while ( $doc = $result->next ) {
61               process_doc($doc)
62           }
63
64       Returns the next document or "undef" if the server cursor is exhausted.
65
66   batch
67         while ( @batch = $result->batch ) {
68           for $doc ( @batch ) {
69             process_doc($doc);
70           }
71         }
72
73       Returns the next batch of documents or an empty list if the server
74       cursor is exhausted.
75
76   all
77           @docs = $result->all;
78
79       Returns all documents as a list.
80

AUTHORS

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