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.

Document collection relationships can be at most 1 deep.
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

Last updated on Dec 19, 2024