1MongoDB::QueryResult(3)User Contributed Perl DocumentatioMnongoDB::QueryResult(3)
2
3
4
6 MongoDB::QueryResult - An iterator for Mongo query results
7
9 version v2.2.1
10
12 $cursor = $coll->find( $filter );
13 $result = $cursor->result;
14
15 while ( $doc = $result->next ) {
16 process_doc($doc)
17 }
18
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
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 NOTE: Per threads documentation, use of Perl threads is discouraged by
47 the maintainers of Perl and the MongoDB Perl driver does not test or
48 provide support for use with threads.
49
50 Iterators are cloned in threads, but not reset. Iterating from
51 multiple threads will give unpredictable results. Only iterate from a
52 single thread.
53
55 has_next
56 if ( $response->has_next ) {
57 ...
58 }
59
60 Returns true if additional documents are available. This will attempt
61 to get another batch of documents from the server if necessary.
62
63 next
64 while ( $doc = $result->next ) {
65 process_doc($doc)
66 }
67
68 Returns the next document or "undef" if the server cursor is exhausted.
69
70 batch
71 while ( @batch = $result->batch ) {
72 for $doc ( @batch ) {
73 process_doc($doc);
74 }
75 }
76
77 Returns the next batch of documents or an empty list if the server
78 cursor is exhausted.
79
80 all
81 @docs = $result->all;
82
83 Returns all documents as a list.
84
86 · David Golden <david@mongodb.com>
87
88 · Rassi <rassi@mongodb.com>
89
90 · Mike Friedman <friedo@friedo.com>
91
92 · Kristina Chodorow <k.chodorow@gmail.com>
93
94 · Florian Ragwitz <rafl@debian.org>
95
97 This software is Copyright (c) 2019 by MongoDB, Inc.
98
99 This is free software, licensed under:
100
101 The Apache License, Version 2.0, January 2004
102
103
104
105perl v5.30.1 2019-12-13 MongoDB::QueryResult(3)