0

Using Doctrine PHPCR-ODM, is there a way to apply a constraint on a property to prevent duplicate values on the same document type ?

For example (getter and setter have been intentionally omitted):

namespace App\Document;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;

/**
 * @PHPCRODM\Document
 */
class Article
{
    /**
     * @PHPCRODM\Field(type="string")
     */
    protected $title;
}

Is there a way to make the title field unique on all the Article documents ?

Damien Flament
  • 1,465
  • 15
  • 27

1 Answers1

0

As far as I know there is not possible to set indexes from Doctrine ODM to a Mongo database (or any other document database). This means that you can define them into your document but you will have to declare these indexes within your mongo database using console.

https://docs.mongodb.com/manual/indexes https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/

Alternatively you can use any of the available mongo clients to create indexes easier using the UI:

http://3t.io/blog/adding-modifying-mongodb-indexes/

manuelbcd
  • 3,106
  • 1
  • 26
  • 39
  • I don't use MongoDB but MySQL as persistence backend. But I'm looking for a solution using PHPC-ODM. Maybe using some third-party library providing custom annotations. – Damien Flament May 31 '17 at 13:00