#!/usr/bin/env perl6
#
use v6;

# Running the pod file will create a pdf using wkhtmltopdf
#
my Str $pod = "$*PROGRAM";
my Str $pdf = $pod;
$pdf ~~ s/\. <-[.]>+ $/.pdf/;
shell( "perl6 --doc=HTML '$pod' | wkhtmltopdf - '$pdf'");

#-------------------------------------------------------------------------------

=begin pod

=head1 NAME MongoDB::Collection - Operations on a MongoDB Collection

=head1 SYNOPSIS

=begin nested
=begin code

use MongoDB;

# Initialize
#
my $connection = MongoDB::Connection.new( );
my $database = $connection.database( 'test' );
my $collection = $database.collection( 'test' );

# Insert documents
#
my %d1 = code           => 'd1'
       , name           => 'name and lastname'
       , address        => 'address'
       , city           => 'new york'
       ;

for ^10 -> $i {
  %d1<test_record> = 'tr' ~ $i;
  $collection.insert(%d1);
}

my $cursor = $collection.find();
say $cursor.count;              # 10.0
#show-documents( $collection, {});

# Find everything
#
my $cursor = $collection.find( );
while $cursor.next( ) -> %document { %document.perl.say; }

=end code
=end nested

=head1 DESCRIPTION

After calling find to query the collection for data a cursor object is
returned. With this cursor it is possible to modify the query or ask
information from the server about the query.

=head1 CLASSES

=for head2
class MongoDB::Cursor does MongoDB::Protocol;

This class has the following attributes.

=for head3
has $.collection;

This is the MongoDB::Collection on which the fetch/next has been executed.

=for head3
has %.criteria;

This is the current search criteria.

=head1 METHODS

=head2 method fetch ( --> Any ) {...}
=head2 method next ( --> Any ) {...}

Get the document from the query. The method returns a document (Hash) or Nil
when no (more) documents are found. Next() does the same as fetch but is added
to mimic the API of the Mongo shell.

=for head2
method explain ( --> Hash ) {...}

Return information on the query plan using the criteria already set in the
cursor. There are many fields in the document. The fields returned also depend
on the type of queries. Look for this information on the L<MongoDB
site|http://docs.mongodb.org/manual/reference/method/cursor.explain>.

=for head2
method hint ( $index-spec, :$explain = False --> Hash ) {...}

Get documents from the database using a hint on what index to use. When
$explain is True, a document of how things are resolved is send instead. See
also L<explain> above. 

=head2 method kill ( --> Nil ) {...}

Delete the cursor when it is no longer needed. By default the server will delete
the cursor after a non-usage period of 10 minutes.

=head2 method count ( Int :$skip = 0, Int :$limit = 0 --> Num ) {...}

Count the number of found documents. This count can be influenced by skip and
limit.

=end pod




