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 5962097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:03:28+00:00 2026-05-22T19:03:28+00:00

I’ve got a problem with Symfony2.0 BETA3 and MongoDB. I want create a Document,

  • 0

I’ve got a problem with Symfony2.0 BETA3 and MongoDB. I want create a Document, where a Field References to another Class, this might look like this:

namespace test\TestBundle\Document;
use test\TestBundle\Document\Location;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ODM\Document(collection="locationcache", repositoryClass="test\TestBundle\Document\LocationCacheRepository")
*/
class LocationCache
{
    // many more fields...

    /**
     * @var Location
     * @ODM\ReferenceOne(targetDocument="test\TestBundle\Document\Location")
     */
    protected $location;

     /**
         * @param Location
     */
    public function setLocation(Location $location)
    {
        $this->location = $location;
    }

    /**
     * @return Location
     */
    public function getLocation()
    {
        return $this->location;
    }
}

But if I want to find a location by $id like this

class LocationCacheRepository extends DocumentRepository
{
    public function findByLocationID(MongoId $locationID)
    {
        return $this->createQueryBuilder()
            ->field('location.$id')->equals($locationID)
            ->sort('year', 'asc')
            ->sort('month', 'asc')
            ->getQuery()
            ->execute();
    }
}

I will get this error

 No mapping found for field 'location' in class 'test\TestBundle\Document\LocationCache'.

UPDATE

Here is a Document

Array
(
    [_id] => 4dd637e706936bbcc0ac012d
    [days] => Array
        (
            [1] => Array
                (
                    [money] => 9
                )

            [2] => Array
                (
                    [money] => 21
                )

            [3] => Array
                (
                    [money] => 38
                )

            [4] => Array
                (
                    [money] => 6
                )

            [18] => Array
                (
                    [money] => 6
                )

            [19] => Array
                (
                    [money] => 3
                )

            [31] => Array
                (
                    [money] => 11
                )

        )

    [location] => Array
        (
            [$ref] => location
            [$id] => 4dd554c91c911a6606000000
            [$db] => test
        )

    [money] => 94
    [month] => 1
    [year] => 2011
)    

I don’t know what’s the problem with the class. Could please someone help?

Thanks in advance!

  • Monty
  • 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-05-22T19:03:28+00:00Added an answer on May 22, 2026 at 7:03 pm

    If you want search on any location field you need to use ’embedOne’ instead of ‘referenceOne’.
    ReferenceOne not copy location fields into parent document, it just data like this (i don’t remember exactly):

    {
     refId: '1',
     refColl: 'locations',
     refDb: 'location_database'
    }
    

    But in general if you need query only by location id you just need take a look how location reference looks like in mongodb using mongoshell or some other tool.

    So you query will be like this:

       ->field('location.$refId')->equals($locationID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.