2

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.

kmfk
  • 3,821
  • 2
  • 22
  • 32

1 Answers1

1

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?).

Ocramius
  • 25,171
  • 7
  • 103
  • 107
Jenna
  • 2,386
  • 17
  • 10
  • Unfortunately this is for the ORM, not ODM. I did look over this a little while ago though. Thanks – kmfk Jul 11 '12 at 18:02
  • Ok, I talked to some colleagues and you can't use ISODates as keys in embedded docs. Could you convert ISODate to a UTC string? You'd also have to make sure your queries are restructured to do range searches for UTC time. – Jenna Jul 11 '12 at 18:38
  • thanks for the reply. I actually edited my question to remove the composite key requirement, as I think I was incorrectly applying the terminology here. Really, in order to group with MapReduce, you end up creating a multi-key object for your collection - I don't believe there is currently any support in Doctrine's ODM code to handle, essentially, an EmbedOne or Hash as a primary key. – kmfk Jul 16 '12 at 01:38
  • 1
    @kmfk: This isn't currently supported. Feel free to open an issue on the [GitHub repository](https://github.com/doctrine/mongodb-odm) so we can track this feature request. – jmikola Jul 29 '12 at 03:55