Document Args
In Cloud Firestore, the unit of storage is the document. A document is a lightweight record that contains fields, which map to values. Each document is identified by a name. To get more information about Document, see:
How-to Guides
Warning: This resource creates a Firestore Document on a project that already has a Firestore database. If you haven't already created it, you may create a
gcp.firestore.Database
resource withtype
set to"FIRESTORE_NATIVE"
andlocation_id
set to your chosen location. If you wish to use App Engine, you may instead create agcp.appengine.Application
resource withdatabase_type
set to"CLOUD_FIRESTORE"
. Your Firestore location will be the same as the App Engine location specified.
Example Usage
Firestore Document Basic
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.firestore.Document;
import com.pulumi.gcp.firestore.DocumentArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var mydoc = new Document("mydoc", DocumentArgs.builder()
.collection("somenewcollection")
.documentId("my-doc-id")
.fields("{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}")
.project("my-project-name")
.build());
}
}
Firestore Document Nested Document
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.firestore.Document;
import com.pulumi.gcp.firestore.DocumentArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var mydoc = new Document("mydoc", DocumentArgs.builder()
.collection("somenewcollection")
.documentId("my-doc-id")
.fields("{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}")
.project("my-project-name")
.build());
var subDocument = new Document("subDocument", DocumentArgs.builder()
.collection(mydoc.path().applyValue(path -> String.format("%s/subdocs", path)))
.documentId("bitcoinkey")
.fields("{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}}}")
.project("my-project-name")
.build());
var subSubDocument = new Document("subSubDocument", DocumentArgs.builder()
.collection(subDocument.path().applyValue(path -> String.format("%s/subsubdocs", path)))
.documentId("asecret")
.fields("{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}")
.project("my-project-name")
.build());
}
}
Import
Document can be imported using any of these accepted formats:
$ pulumi import gcp:firestore/document:Document default {{name}}