The JVM SDK currently only supports legacy versions of Nitric prior to v1. This version is maintained for compatibility with existing projects and not recommended for new projects. New projects should be started using a supported SDK (presented automatically using the `nitric new` command) orget in touch to request an update to the latest version.
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();
}
}