Some time ago I was posting answer to similar question on StackOverflow 
(http://stackoverflow.com/a/42317991/5982920), for the sake of completness 
I'll copy it here: 

Identifier is automatically mapped as _id field therefore there can be only 
1 field mapped as @Id. 


Done similar things in the past and I'd suggest keeping \MongoId as 
document identifier and generating incremented customerId in your code 
instead of relying on ODM to do so. Making such generator is pretty 
straightforward, you need to hook into persisting document (be it in your 
domain code, which I advice, or leveraging prePersist event) and write 
generator similar to ODM's IncrementGenerator 
<https://github.com/doctrine/mongodb-odm/blob/a250f14f899931fcb21ee0af6d2e490f589b2051/lib/Doctrine/ODM/MongoDB/Id/IncrementGenerator.php#L53>
.


On Friday, 24 March 2017 12:32:22 UTC+1, Derek ROTH wrote:
>
> Hi,
>
> Did you find a solution to this issue ?
>
> Le lundi 9 juillet 2012 12:39:43 UTC+2, Phil Moorhouse a écrit :
>>
>> Is it possible to have both an $id field that uses MongoID and an 
>> automatically managed auto-increment integer field (lets call it $key) in 
>> the same document?
>>
>> I'd like to keep the MongoIds available internally but I also need 
>> something to use in the URL for my REST API because the MongoIds are too 
>> long and ugly. A simple auto-incrementing integer would suffice.
>>
>> I've tried this with:
>>
>>     /**
>>      * @MongoDB\Id(strategy="AUTO")
>>      * @JMSType("string")
>>      * @JMSExclude
>>      */
>>     protected $id;
>>
>>     /**
>>      * @MongoDB\Id(strategy="INCREMENT")
>>      * @JMSType("integer")
>>      */
>>     protected $key;
>>
>> and 
>>
>>     /**
>>      * @MongoDB\Int(strategy="INCREMENT")
>>      * @JMSType("integer")
>>      */
>>     protected $key;
>>
>> but only the $id field ever gets created in MongoDB, the $key field 
>> doesn't exist. I noticed that if I set the $id to INCREMENT, then Doctrine 
>> creates another collection in MongoDB for implementing the side-counter 
>> pattern described here: 
>> http://www.mongodb.org/display/DOCS/How+to+Make+an+Auto+Incrementing+Field. 
>> Is there any way to set up a field to use this strategy without overriding 
>> the main ID?
>>
>>
>> Cheers,
>> Phil
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to