MongoD...Result(3pm)
π MongoDB::QueryResult π
okay bestie, so this page? it's MongoD...Result(3pm), from the User Contributed Perl Documentation manual, and it's literally all about MongoDB::QueryResult β the iterator that goes brrr over your Mongo query results. yes we're doing this. grab a snack. π
β¨ NAME β¨
MongoDB::QueryResult β an iterator for Mongo query results. that's it, that's the whole job. it iterates. it serves. π
π VERSION π
version v2.2.2 β she's at v2.2.2, periodt.
π¦ SYNOPSIS π¦
$cursor = $coll->find( $filter );
$result = $cursor->result;
while ( $doc = $result->next ) {
process_doc($doc)
}
like... she's so simple. get your cursor, grab the result, loop while next keeps handing you docs. main character behaviour honestly.
π DESCRIPTION π
So this class defines an iterator that runs against a query result. and the slay part? it automatically fetches additional results from the originating mongod/mongos server on demand. no cap, it just goes and gets more when it needs more. π«Ά
Now, for backwards compatibility reasons, MongoDB::Cursor encapsulates the query parameters and generates a MongoDB::QueryResult object on demand. and literally every iterator on MongoDB::Cursor delegates to a MongoDB::QueryResult object. so it's the same energy, just one layer of middle-management away. π
Retrieving this object and iterating on it directly will be slightly more efficient. cut out the middleman, get the gains. β¨
π USAGE π
π Error handling
Unless it's otherwise explicitly documented, all methods throw exceptions if an error occurs. all of them. no silent failures here, she is LOUD.
The error types are documented in MongoDB::Error.
To catch and handle those errors, the Try::Tiny and Safe::Isa modules are recommended. use them, bestie. your future self will thank you. πΈ
π§ Cursor destruction
When a MongoDB::QueryResult object is destroyed, a cursor termination request gets sent to the originating server to free server resources. it's polite. it cleans up after itself. we love a tidy queen. π
β οΈ Multithreading
NOTE: per the threads documentation, use of Perl threads is discouraged by the maintainers of Perl, and the MongoDB Perl driver does not test or provide support for use with threads. so like... not our problem, but also, don't.
Iterators are cloned in threads, but not reset. Iterating from multiple threads will give unpredictable results. Only iterate from a single thread. do not text the group chat from four phones at once. π
π METHODS π
π has_next
if ( $response->has_next ) {
...
}
Returns true if additional documents are available. and the way she does it? she'll attempt to get another batch of documents from the server if necessary. a little extra hustle when needed. π
π next
while ( $doc = $result->next ) {
process_doc($doc)
}
Returns the next document, or undef if the server cursor is exhausted. that undef is your signal that the party's over. π
π batch
while ( @batch = $result->batch ) {
for $doc ( @batch ) {
process_doc($doc);
}
}
Returns the next batch of documents, or an empty list if the server cursor is exhausted. bulk delivery. she's bringing the whole tray, not one lil drink. π
π all
@docs = $result->all;
Returns all documents as a list. every single one. the whole entire roster, right now, in one go. π₯
π«Ά AUTHORS π«Ά
- David Golden <david@mongodb.com>
- Rassi <rassi@mongodb.com>
- Mike Friedman <friedo@friedo.com>
- Kristina Chodorow <k.chodorow@gmail.com>
- Florian Ragwitz <rafl@debian.org>
look at them. the icons who built this. respect. π
π 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
okay that's the whole page bestie, go iterate responsibly π
and for the cute sign-off: this one's from perl v5.40.1, dated 2025-04-03, and she answers to the name MongoD...Result(3pm). bye bestie, slay, and remember β only iterate from a single thread. β¨ππ¦
π¦ where this page comes from
- debian trixie: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- ubuntu resolute: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- ubuntu stonking: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms