0

I am new in mongodb.I run following query and my system will hangs.

$products = $this->get('doctrine_mongodb')
    ->getManager()
    ->createQueryBuilder('AcmeStoreBundle:Product')
    ->field('name')->equals('foo')
    ->limit(10)
    ->sort('price', 'ASC')
    ->getQuery()
    ->execute();
   echo "<pre>";print_r($products);die; 

I got this:

Doctrine\ODM\MongoDB\Cursor Object
(
    [baseCursor:Doctrine\ODM\MongoDB\Cursor:private] => Doctrine\MongoDB\LoggableCursor Object
        (
            [loggerCallable:protected] => Array
                (
                    [0] => Doctrine\Bundle\MongoDBBundle\Logger\AggregateLogger Object
                        (
                            -----so on

Where is the result?

1
  • How many records are in Mongo; how many are you expecting on the output? Commented Aug 19, 2015 at 7:20

1 Answer 1

2

Do you have any other information to give us ? Do you have any error output?

Edit

For a single result you should use :

$products = $this->get('doctrine_mongodb')
->getManager()
->createQueryBuilder('AcmeStoreBundle:Product')
->field('name')->equals('foo')
->limit(1)
->sort('price', 'ASC')
->getQuery()
->getSingleResult();

For multiple results your code is good but you should iterate over the returned Cursor to get your data.

Edit 2

$products = $this->get('doctrine_mongodb')
->getManager()
->createQueryBuilder('AcmeStoreBundle:Product')
->field('name')->equals('foo')
->limit(1)
->sort('price', 'ASC')
->getQuery()
->execute();

foreach ($products as $product) {
    var_dump($product);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.