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

  • Home
  • SEARCH
  • 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 8107197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:41:19+00:00 2026-06-06T00:41:19+00:00

I am using mongoDB for a new project at work and I got into

  • 0

I am using mongoDB for a new project at work and I got into some troubles which I can’t find any solutions for. I have a model in my project which contains a method to fetch some data from MongoDB, which works just fine as long as I use findOne() instead of find().

The method:

public function getData($input) {

        $output = $this->_collection->find($input);
        //$output = $this->_collection->findOne($input);
        Zend_Debug::Dump($output);
        return $output;
    }

When running that piece of code I get this from the dump:

object(MongoCursor)#52 (0) {
}

Using findOne() :

array(12) {
  ["_id"] => object(MongoId)#54 (1) {
    ["$id"] => string(24) "4fd85d178efd307080000001"
  }
  ["autoadd"] => string(1) "1"
  ["name"] => string(5) "Sport"
  ["keyword"] => string(8) "cookie29"
  ["antal"] => string(1) "0"
  ["antal_week_date"] => string(10) "1218818007"
  ["version"] => string(1) "1"
  ["active"] => string(1) "1"
  ["antal_week"] => string(1) "0"
  ["customer_id"] => string(1) "2"
  ["id"] => string(2) "29"
  ["insert_date"] => string(10) "2007-11-21"
}

And when using $output = $this->_collection->find($input)->count();:

int(20)

What am I doing wrong? This might be a simple problem, but I can’t find any other way to do this stuff. If you wonder what the input is, it’s just an associative array:

$data = array('active' => '1');

Please help me fetch all those 20 nice “rows” of data.
I’d be grateful.

Thanks for your advice and better wisdom!

  • 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-06T00:41:20+00:00Added an answer on June 6, 2026 at 12:41 am

    find() returns cursor, not the array with actual data. You have to iterate the cursor. This is an example from the documentation

    $m = new Mongo();
    $db = $m->selectDB('test');
    $collection = new MongoCollection($db, 'phpmanual');
    
    // search for documents where 5 < x < 20
    $rangeQuery = array('x' => array( '$gt' => 5, '$lt' => 20 ));
    
    $cursor = $collection->find($rangeQuery);
    foreach ($cursor as $doc) {
        var_dump($doc);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using mongodb and I have changed the dbpath. Can I just copy
First some context: I have an MVC3 .net project which, for the sake of
Im using mongodb + java. I tried to insert a new document into an
I'm considering using mongodb on a new project, but before delving in, I'd like
I'm new to rails application. I got connection with mongodb using mongoid. I generated
I'm using mongodb 2.1 and how to translate this query into php db.counter.aggregate([ {
I'm using MongoDB as a backend for my project, but I don't specifically want
I am using MongoDB to store data. In my project I am connecting multiple
I'm new to Rails development and I'm starting with MongoDB also. I have been
I'm designing a new web project and, after studying some options aiming scalability, I

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.