error = MongoId not found in symfony application

I got the MongoId not found error on the the application I recently moved to remote server.
The app is working fine locally and the problem appears to happen on the remote one only.
The problem seems obvious, and I checked the mongo version I have locally vs the version I have on the remote – they are different

I have newer version of mongo installed on the remote server. And the doctrine orm handling my mongo objects was also older.
I updated my doctrie orm on composer as

 "doctrine/orm": "2.4.6",

This took care of the problem – at least for now 😉

A new entity was found through the relationship doctrine error

Doctrine error: New Entity was found through relationship

This is typical problem of doctrine with joined relations.

How to use MySQL keyword as column in doctrine

And, to be specific, this would happen when trying to save an entity with relationship and the one being joined is fetched from memcached/redis or from other entity manager or you just populated it and not getting through Entity Manager

Solution to the doctrine error

Use the merge on EntityManager before you persist the object

Say you have an entity for pen and entity for color as well.. You want to save a new pen but you assigned a color from memcached object


$color = $this->memcacheGiveMeColor('blue');
$color = $em->merge($color)
$pen->setColor($color);
$em->persist($pen);
$em->flush();

Make sure you are using the object that is returned from merge!

If you are not reading from the memcached or other factory, and you are reading directly from Entity Manager then you wont have this error.

Start using mongoDB with nodeJS even though you haven’t been using it before

What is http raw data? what is php://input and where to use which?

Doctrine orm:convert-mappings errors on primary key

Doctrine error orm:convert-mappings

Doctrine orm error like above? I have been there.

The solution I am providing is not that great solution but it can keep you going for a while.

A tool for generating entities for doctrine orm from the database table without primary key might complain as:

has no primary key. Doctrine does not support reverse engineering from tables that don’t have a primary key.

From the code base search for DatabaseDriver.php file:

Go to DatabaseDriver.php

Search for reverseEngineerMappingFromDatabase method in the given file.

uncomment the the following part as follows

           //if ( ! $table->hasPrimaryKey()) {
              //  throw new MappingException(
                //    "Table " . $table->getName() . " has no primary key. Doctrine does not ".
                  //  "support reverse engineering from tables that don't have a primary key."
                //);
            //}

            //$pkColumns = $table->getPrimaryKey()->getColumns();

Add the following line

$pkColumns = array();

Then search for method getTablePrimaryKeys and comment everything inside it and return empty array.

The above method will remove the has no primary key. Doctrine does not support reverse engineering from tables that don’t have a primary key. error when using entity generation tool.

Fatal error: require(): Failed opening required Hydrator in mongodb

I was working on putting POPO to MongoDB in symfony project.
I have the Document inside BundleDocumentMyDocument.php

I want to create this document for the first time, but would like to update the document if it exists based on its two fields like:
* I have taken out some of additional information and focus on the main code only..

$file_id = getTheFileId();
$accessor_id = getAccessorId();
$repository=$this->getMongoService()
				->getManager()
				->getRepository('SomethinSomethingBundleDocumentFileAccess');
			$file_access=$repository->findOneBy(array('fileId'=>$file_id, 'accessorId'=>$accessor_id));
			if ($file_access && $file_access instanceof FileAccess){
				$file_access->setAccessCount($file_access->getAccessCount()+1);
			}else{
				$file_access=new FileAccess();
				$file_access->setFileId($file_id);
				$file_access->setAccessorId($accessor_id);
				$file_access->setAccessorType(FileAccess::ACCESS_TYPE_MEMBER);
				$file_access->setAccessDate(time());
				$file_access->setAccessCount(1);
			}
			$document_manager=$this->getMongoService()->getManager();
			$document_manager->persist($file_access);
			$document_manager->flush();

The problem I was facing was when I try to access the record, not when I was adding it.
and I know the record was there by using the command line mongo tool

The solution appears to be the missing config item for mongo:
on your config for mongo add

auto_generate_hydrator_classes: true

and that should fix the problem.

Single id is not allowed on composite primary key in entity Doctrine error

You might get the above error on PHP Doctrine

if you got the above error, then it means you have two or more ids as primary in your object representing the table.

Example:

class Member
   /** @id 
    * @Column(type="integer") 
    * @GeneratedValue(strategy="AUTO")
    */
   private $id;
   /** @id @Column(type="string") */
   private $key;
...

The above declaration would create the above error and taking out the generatedValue part can resolve the issue.

See the solution to common error of new entity was found though relation while using doctrine