JVM - collection()
Creates a new Collection.
import io.nitric.Nitric;import io.nitric.resources.CollectionPermission;// A user class to store in the profiles collectionclass 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, CollectionPermission.Write, CollectionPermission.Delete);Nitric.INSTANCE.run();}}
Parameters
- Name
name
- Required
- Required
- Type
- String
- Description
The unique name of this Collection within the app. Subsequent calls to
collection
with the same name will return the same object.
- Name
type
- Required
- Required
- Type
- Class<T>
- Description
The type of documents that will be stored in the collection.
Access
All Nitric resources provide access permissions you can use to specify the level of access your code needs to the resource. See here for details about infrastructure security.
Available permissions:
CollectionPermission.Read
This permission allows your code to read and query documents from the collection.
CollectionPermission.Write
This permission allows your code to write documents to the collection.
CollectionPermission.Delete
This permission allows your code to delete documents from the collection.
Examples
Create a collection
import io.nitric.Nitric;import io.nitric.resources.CollectionPermission;// A user class to store in the profiles collectionclass 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, CollectionPermission.Write, CollectionPermission.Delete);Nitric.INSTANCE.run();}}
Last updated on Feb 15, 2025