Skip to content

Question: How to deal with inconsistent document structures with EmbedMany/EmbedOne  #1396

Closed
@araines

Description

@araines

I appreciate this is probably a little bit of an odd use-case, but its something I'm struggling with and would love it if someone had an idea which might help.

The issue I have is that I'm trying to integrate ODM on top of a legacy system which has documents stored where the embedded document can be either an object (in the case where there was only one) or an array (in the case where there was many). For reasons I won't go in to, migrating or altering the legacy system which creates these documents is not an option.

I've got a document set up as so:

class Competition
{
    /**
     * @MongoDB\EmbedMany(targetDocument="TeamStanding", name="TeamStandings")
     */
    private $teamStandings = [];

    /**
     * @MongoDB\EmbedOne(targetDocument="TeamStanding", name="TeamStandings")
     */
    private $teamStanding;

Because these are both linked to the same json node TeamStandings, only one takes effect. For reference the document structure looks something like:

{
  "TeamStandings": {
      // team standing
  }
}

or

{
  "TeamStandings": [
    {
      // team standing 1
    },
    {
      // team standing 2
    }
}

It seems like I need something like an "EmbedManyOrOne" annotation! All and any suggestions are appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions