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
}
nitric.Run()
}

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

Last updated on Dec 5, 2024