0

I am, trying to increment the field, and get no results; Here is my code:

class Query
{
    /**
     * @ODM\Id
     */
    protected $id;

    /**
     * @ODM\Field(type="int", strategy="increment")
     *
     */
    protected $my_id = 0;

    public function incrementMyId()
    {
        $this->my_id++;
    }
}

When in action i try:

$query = new Query(); 
$query->incrementMyId(); 
$this->documentManager->persist($query);
$this->documentManager->flush();

The field my_id is always equals to int(1); Can u help me with this issue? Thanks.

I use ZF3,

"alcaeus/mongo-php-adapter": "^1.
"doctrine/doctrine-mongo-odm-module": "^0.11.
"doctrine/mongodb-odm": "^1.1"

ipave
  • 1,249
  • 9
  • 17

1 Answers1

1

Strategy increment for a normal field means that the query updating document in the database will use $inc operator instead of $set, exactly as per documentation.

You seem to want to have both auto-generated ObjectId identifier and unique auto-incremented one for the entire collection. For such usage please see my other answer to a similar question

Community
  • 1
  • 1
malarzm
  • 2,831
  • 2
  • 15
  • 25