[perl] Trying to print all ids. What am I doing wrong?

11 views
Skip to first unread message

Amadeus

unread,
Sep 6, 2010, 10:52:51 AM9/6/10
to mongodb-user
Hi,

I am completely new to MongoDB, so first of all I want to print all
ID's in an existing MongoDB using Perl.

The following script prints

HASH(0x12e2e9f0)

25 times. I would have expected to see 25 different ID's.

Any idea what's wrong?

Best regards,
Amadeus


#!/usr/bin/perl
use MongoDB;
use MongoDB::OID;

my $conn = MongoDB::Connection->new;
my $db = $conn->piwik;

my $visits = $db->visits;
my $all_visit_ids = $visits->find;

while (my $doc = $all_visit_ids->next) {
print $doc . "\n";
}


J Greely

unread,
Sep 6, 2010, 1:45:13 PM9/6/10
to mongodb-user


On Sep 6, 7:52 am, Amadeus <sha256...@gmail.com> wrote:
> Any idea what's wrong?

Because you retrieved the entire object as a reference to a hash, not
the Object ID as a string.

>     print $doc . "\n";

print $doc->{_id},"\n";

-j

Amadeus

unread,
Sep 6, 2010, 4:20:40 PM9/6/10
to mongodb-user
Thank you very much! =)

Reply all
Reply to author
Forward
0 new messages