I am quite new to MongoDB and thus to this list so let me say hi!
I've started to build a small application using MongoDB but now as I
try to fetch a list of distinct values I hit a wall.
I managed to used the mongo client to fetch the distinct values but I
am not sure how should I do it in Perl.
The distinct method seems to be accepted but it returns a
MongoDB::Collection and I don't know how
to fetch the data from there. Besides, I also got an exception.
Sample code:
use strict;
use warnings;
use MongoDB;
my $connection = MongoDB::Connection->new(host => 'localhost', port => 27017);
my $db = $connection->test;
$db->insert({ 'name' => 'a', code => 1 });
$db->insert({ 'name' => 'b', code => 1 });
$db->insert({ 'name' => 'c', code => 2 });
my $distinct = $db->distinct('code');
print "$distinct\n"; # MongoDB::Collection=HASH(0x14f4798)
my $r1 = $distinct->find();
print "$r1\n"; # MongoDB::Cursor=HASH(0x853260)
while (my $d = $r1->next) {
print "$d\n";
}
my $r2 = $distinct->find('code');
print "R2: $r2\n"; # MongoDB::Cursor=HASH(0x853260)
while (my $d = $r2->next) {
print "D: $d\n";
}
# throws an exception:
# not a reference at
/home/gabor/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/MongoDB/Cursor.pm
line 231.
print "done\n";
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
thanks.
Except of the dump($r3) part this works and shows what I needed.
Maybe Kristina could include this as an example in the CPAN distribution.
regards
Gabor