JVM - collection.doc.collection()

Gets a reference to a child collection on a document.

import io.nitric.Nitric;
import io.nitric.resources.CollectionPermission;

class User {
  String name;
  int age;

  public User(String name, int age) {
    this.name = name;
    this.age = age;
  }
}

public class Application {
  public static void main(String[] args) {
    var profiles = Nitric.INSTANCE.collection("profiles", User.class).with(CollectionPermission.Read);

    var drakesProfile = profiles.doc("Drake Mallard");

    var drakesEnemies = drakesProfile.collection("enemies", User.class);

    Nitric.INSTANCE.run();
  }
}

Parameters

  • Name
    name
    Required
    Required
    Type
    String
    Description

    The name of the child collection to reference

  • Name
    type
    Required
    Required
    Type
    Class<T>
    Description

    The type of documents that will be stored in the collection.

import io.nitric.Nitric;
import io.nitric.resources.CollectionPermission;

class User {
  String name;
  int age;

  public User(String name, int age) {
    this.name = name;
    this.age = age;
  }
}

public class Application {
  public static void main(String[] args) {
    var profiles = Nitric.INSTANCE.collection("profiles", User.class).with(CollectionPermission.Read);

    profiles
      .doc("Drake Mallard")
      .collection("enemies", User.class))
      .doc('Steel Beak') // โœ”๏ธ We can go this deep
      .collection('enemies', User.class) // โŒ But not this deep

    Nitric.INSTANCE.run();
  }
}

See also