Go - Collection.Doc.Collection()

Gets a reference to a child collection on a document.

import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  profiles, err := nitric.NewCollection("profiles").With(nitric.CollectionReading)
  if err != nil {
    return
  }

  drakesEnemiesCollection, err := profiles.Doc("Drake Mallard").Collection("enemies")
  if err != nil {
    return
  }

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}

Parameters

  • Name
    name
    Required
    Required
    Type
    string
    Description

    The name of the child collection to reference

Notes

Document collection relationships can be at most 1 deep.

// โœ”๏ธ We can go this deep
drakesEnemiesCollection, err := profiles.Doc("Drake Mallard").Collection("enemies")
if err != nil {
  fmt.Println(err)
  return
}

// โŒ But not this deep
drakesEnemiesEnemiesCollection, err := drakesEnemiesCollection.Doc("Steel Beak").Collection("enemies")
if err != nil {
  fmt.Println(err)
  return
}

See also