V MongoDB driverech source:lib/Mentat/Storage/Mongo.pm a source:lib/Mentat/Message/Storage/Mongo.pm jsem naimlementoval novou metodu pro vyhledávání a iterativní procházení výsledkem. commit:6b41454c
Způsob použití je dokumentován u příslušných modulů, ale jelikož to nikdo nečte, tak to radši uvedu i zde:
#General Mentat::Storage::Mongo engine:
# Using iteration on cursor, arguments are the same as with find() method
my @result = [];
my ($cursor, $cnta) = $engine->find_i();
# !!!PREFERED METHOD!!! Now either use internal cursor iteration with optional limit
# This method uses the closures @result is visible in callback method
sub cb($) {
push(@result, @_); # OR DO SOME OTHER STUFF HERE
}
my $cntb = $engine->cursor_iterate($cursor, \&cb, $limit);
# !!!DISCOURAGED METHOD!!! Or use cursor directly
while (my $doc = $cursor->next) {
push(@result, $doc); # OR DO SOME OTHER STUFF HERE
}
# @result now contains all data
# Message specific Mentat::Message::Storage::Mongo:
# Example of iterative find with conversion from database document to message
my @result = [];
my ($cursor, $cnta) = $engine->find_i();
# !!!PREFERED METHOD!!! Now either use internal cursor iteration with optional limit
# This method uses the closures @result is visible in callback method
sub cb($) {
my $m = $engine->objectify(@_);
push(@result, $m); # OR DO SOME OTHER STUFF HERE
}
my $cntb = $engine->cursor_iterate($cursor, \&cb, $limit);
# !!!DISCOURAGED METHOD!!! Or use cursor directly
while (my $doc = $cursor->next) {
my $m = $engine->objectify($doc);
push(@result, $m); # OR DO SOME OTHER STUFF HERE
}
# @result now contains all data