Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9131485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:08:56+00:00 2026-06-17T08:08:56+00:00

I read http://api.mongodb.org/perl/current/MongoDB/Examples.html and seems to be only documentation from mongoDB on Perl. How

  • 0

I read http://api.mongodb.org/perl/current/MongoDB/Examples.html and seems to be only documentation from mongoDB on Perl. How do I get my query result from mongoDB in perl. Let us say into Hash. I have successfully made connection to the db so far. I managed to do inserts into collections. Now how do I issue select query and get its returned data into hash or something similar?

Update:

Example of my data
{
 "_id" : ObjectId("asdhgajsdghajgh"),
 "country" : "USA"
 "city" : "Boston"
}

{
 "_id" : ObjectId("asdhgajsdghajgh"),
 "country" : "USA"
 "city" : "Seattle"
}

{
 "_id" : ObjectId("asdhgajsdghajgh"),
 "country" : "Canada"
 "city" : "Calgary"
}

My code

my $cursor = $my_collection
    ->find({ country => 1 }) 
    ;
while (my $row = $cursor->next) {
    print "$row\n";
}

This code is not resulting any output.
I want to basically iterate through the entire collection and read document by document.
Not sure what I am doing wrong. I used the code above. I changed $cur->next to $cursor->next I am guessing it was a typo. I appreciate all the answers so far.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:08:57+00:00Added an answer on June 17, 2026 at 8:08 am

    That’s not the official documentation. Head right to the CPAN:

    • MongoDB::Tutorial
    • MongoDB::Examples

    Iterating results is pretty similar to the DBI way:

    use Data::Printer;
    use MongoDB;
    
    # no query is performed on initialization!
    my $cursor = $collection
        ->find({ active => 1, country => 'Canada' }) # filter "active" records from Canada
        ->sort({ stamp => -1 }) # order by "stamp" attribute, desc.
        ->limit(1000);          # first 1000 records
    
    # query & iterate
    while (my $row = $cur->next) {
        # it is 'p', from Data::Printer!
        p $row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read the documentation at http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html , but don't understand when the around_*
I read this: http://symfony.com/doc/current/book/service_container.html It said: $mailer = $this->get('my_mailer'); As an added bonus, the
I've read http://wxpython.org/docs/api/wx.ConfigBase-class.html I've done some basic things like the appended. What I can
I've read the API documentation on .stop()... http://api.jquery.com/stop/ But I'm still confused as to
I don't see anything in the read API that provides access to this: http://api.dojotoolkit.org/jsdoc/1.3.2/dojo.data.api.Read
So, here is the discussion I have just read: http://www.mail-archive.com/delphi@delphi.org.nz/msg02315.html BeginUpdate and EndUpdate is
I get this error : java.net.SocketTimeoutException: Read timed out http://api.trove.nla.gov.au/result?key=<KEY HERE>&zone=all&reclevel=brief&q=%20am%20only%20yours%20fear&encoding=json Exception in thread
The following is the XML file read into XmlDocument <Test xmlns=http://api.test.com/v2 xmlns:i=http://www.w3.org/2001/XMLSchema-instance> <Result id=2015
I'm having troubles reading from this api http://api.xhanch.com/islamic-get-prayer-time.php?lng=67&lat=24&yy=2012&mm=7&gmt=5&m=json Here's my code: new Read().execute(sunrise); public
I am in the process of creating a RESTful API. I read http://microformats.org/wiki/rest/urls but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.