Keeping multiple types in a single collection

I’ve got a schema that looks like the following:

type LatData {
    LatResults: [[Int ]] 
    LatResultSize: [Int ] 
}

type AggregateData { 
    EVRCounter: Int
    EVRLatencyTotal: Int
    EVRLatencyAverage: Float
    LatTestCount: Int
    LatencyTotal: Int
    LatencyAverage: Float 
}

type MetaData { 
    StartTimeUTC: String
    EndTimeUTC: String
    StartTimeLocal: String
    EndTimeLocal: String 
}

type BenchmarkDatasets { 
    LatData: LatData
    AggregateData: AggregateData
    MetaData: MetaData
}

type Query {
  allBenchmarkDatasets: [BenchmarkDataset!]
}

I want to keep all of these types in a single collection named “BenchmarkDatasets”. Do I need to declare the subtypes(LatData, AggregateData, MetaData) differently or do I just need to accept that I’ll have a collection for every type?

Any help is greatly appreciated.

Hi @Skewjo,

you have to use a schema like this:

 type LatData @embedded {
    LatResults: [[Int ]] 
    LatResultSize: [Int ] 
}

type AggregateData @embedded {
    EVRCounter: Int
    EVRLatencyTotal: Int
    EVRLatencyAverage: Float
    LatTestCount: Int
    LatencyTotal: Int
    LatencyAverage: Float 
}

type MetaData @embedded {
    StartTimeUTC: String
    EndTimeUTC: String
    StartTimeLocal: String
    EndTimeLocal: String 
}

type BenchmarkDatasets { 
    LatData: LatData
    AggregateData: AggregateData
    MetaData: MetaData
}

type Query {
  allBenchmarkDatasets: [BenchmarkDatasets!]
}

and inserting

mutation CreateDS {
  createBenchmarkDatasets(
    data: {
      LatData: {
        LatResults:[1,2,3,4]
        LatResultSize:4
      }
      AggregateData: {
        EVRCounter: 5
    		EVRLatencyTotal: 3
    		EVRLatencyAverage: 2.1
    		LatTestCount: 7
    		LatencyTotal: 2
    		LatencyAverage: 5.6 
      }
      MetaData: {
        StartTimeUTC: "today"
    		EndTimeUTC: "tomorrow"
    		StartTimeLocal: "locStartTime"
    		EndTimeLocal: "locEndTime"
      }
    }
  ) {
    _id
  }
}

The inserted document looks like this one:

{
  "ref": Ref(Collection("BenchmarkDatasets"), "283609220298834433"),
  "ts": 1606729679390000,
  "data": {
    "LatData": {
      "LatResults": [
        [
          1
        ],
        [
          2
        ],
        [
          3
        ],
        [
          4
        ]
      ],
      "LatResultSize": [
        4
      ]
    },
    "AggregateData": {
      "LatencyTotal": 2,
      "EVRLatencyAverage": 2.1,
      "EVRLatencyTotal": 3,
      "LatTestCount": 7,
      "EVRCounter": 5,
      "LatencyAverage": 5.6
    },
    "MetaData": {
      "StartTimeUTC": "today",
      "EndTimeUTC": "tomorrow",
      "StartTimeLocal": "locStartTime",
      "EndTimeLocal": "locEndTime"
    }
  }
}

Hope this helps.

Luigi

Thank you Luigi, the @embedded directive was exactly what I needed.