mongodbsymfonydoctrine-ormdoctrine-odm

Doctrine2 ODM - Object ( or Embedded Document ) as _id


I have a process running an incremental map reduce to a collection where I am looking at metrics over different time periods - grouping by id(s) and date. So my output collection essentially has a composite id to handle the grouping.

{
    "_id" : {
        "site" : 67,
        "dt" : ISODate("2012-07-03T00:00:00Z")
    },
    "value" : {
        // Metrics here
    }
}

I want to be able to fetch results from this collection in my Symfony2 app using the ODM - but having trouble with the _id field. I thought I might be able to specify it as an @Id and @embedOne:

   /**
    * @MongoDB\Id
    * @MongoDB\EmbedOne(targetDocument="reportId")
    */
   protected $id;

However, this doesn't work. I also tried setting @Id with strategy=NONE, and I can use the QueryBuilder to fetch rows, but it errors when trying to hydrate my Document class. I tried slugging the site id and date ( 67-134137916 ) and it allows me to use the DocumentManager, but I lose the ability to query by date ranges.

Anyone have any input on how to handle an object as an id in Doctrine2's ODM, is this supported?

edit: Removed composite primary key tag - question really pertains to using an object as a primary key.


Solution

  • I'm not sure if this gets at the heart of your question: Composite Primary Keys tutorial

    It looks like you can only have composite primary keys of integers and strings (so no dates?).