1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. firestore
  5. Document
Google Cloud Classic v6.66.0 published on Monday, Sep 18, 2023 by Pulumi

gcp.firestore.Document

Explore with Pulumi AI

gcp logo
Google Cloud Classic v6.66.0 published on Monday, Sep 18, 2023 by Pulumi

    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:

    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 with type set to "FIRESTORE_NATIVE" and location_id set to your chosen location. If you wish to use App Engine, you may instead create a gcp.appengine.Application resource with database_type set to "CLOUD_FIRESTORE". Your Firestore location will be the same as the App Engine location specified.

    Example Usage

    Firestore Document Basic

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Gcp = Pulumi.Gcp;
    
    return await Deployment.RunAsync(() => 
    {
        var mydoc = new Gcp.Firestore.Document("mydoc", new()
        {
            Collection = "somenewcollection",
            DocumentId = "my-doc-id",
            Fields = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}",
            Project = "my-project-name",
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/firestore"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := firestore.NewDocument(ctx, "mydoc", &firestore.DocumentArgs{
    			Collection: pulumi.String("somenewcollection"),
    			DocumentId: pulumi.String("my-doc-id"),
    			Fields:     pulumi.String("{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}"),
    			Project:    pulumi.String("my-project-name"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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());
    
        }
    }
    
    import pulumi
    import pulumi_gcp as gcp
    
    mydoc = gcp.firestore.Document("mydoc",
        collection="somenewcollection",
        document_id="my-doc-id",
        fields="{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}",
        project="my-project-name")
    
    import * as pulumi from "@pulumi/pulumi";
    import * as gcp from "@pulumi/gcp";
    
    const mydoc = new gcp.firestore.Document("mydoc", {
        collection: "somenewcollection",
        documentId: "my-doc-id",
        fields: "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}",
        project: "my-project-name",
    });
    
    resources:
      mydoc:
        type: gcp:firestore:Document
        properties:
          collection: somenewcollection
          documentId: my-doc-id
          fields: '{"something":{"mapValue":{"fields":{"akey":{"stringValue":"avalue"}}}}}'
          project: my-project-name
    

    Firestore Document Nested Document

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Gcp = Pulumi.Gcp;
    
    return await Deployment.RunAsync(() => 
    {
        var mydoc = new Gcp.Firestore.Document("mydoc", new()
        {
            Collection = "somenewcollection",
            DocumentId = "my-doc-id",
            Fields = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}",
            Project = "my-project-name",
        });
    
        var subDocument = new Gcp.Firestore.Document("subDocument", new()
        {
            Collection = mydoc.Path.Apply(path => $"{path}/subdocs"),
            DocumentId = "bitcoinkey",
            Fields = "{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}}}",
            Project = "my-project-name",
        });
    
        var subSubDocument = new Gcp.Firestore.Document("subSubDocument", new()
        {
            Collection = subDocument.Path.Apply(path => $"{path}/subsubdocs"),
            DocumentId = "asecret",
            Fields = "{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}",
            Project = "my-project-name",
        });
    
    });
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/firestore"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		mydoc, err := firestore.NewDocument(ctx, "mydoc", &firestore.DocumentArgs{
    			Collection: pulumi.String("somenewcollection"),
    			DocumentId: pulumi.String("my-doc-id"),
    			Fields:     pulumi.String("{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}"),
    			Project:    pulumi.String("my-project-name"),
    		})
    		if err != nil {
    			return err
    		}
    		subDocument, err := firestore.NewDocument(ctx, "subDocument", &firestore.DocumentArgs{
    			Collection: mydoc.Path.ApplyT(func(path string) (string, error) {
    				return fmt.Sprintf("%v/subdocs", path), nil
    			}).(pulumi.StringOutput),
    			DocumentId: pulumi.String("bitcoinkey"),
    			Fields:     pulumi.String("{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}}}"),
    			Project:    pulumi.String("my-project-name"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = firestore.NewDocument(ctx, "subSubDocument", &firestore.DocumentArgs{
    			Collection: subDocument.Path.ApplyT(func(path string) (string, error) {
    				return fmt.Sprintf("%v/subsubdocs", path), nil
    			}).(pulumi.StringOutput),
    			DocumentId: pulumi.String("asecret"),
    			Fields:     pulumi.String("{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}"),
    			Project:    pulumi.String("my-project-name"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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 pulumi
    import pulumi_gcp as gcp
    
    mydoc = gcp.firestore.Document("mydoc",
        collection="somenewcollection",
        document_id="my-doc-id",
        fields="{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}",
        project="my-project-name")
    sub_document = gcp.firestore.Document("subDocument",
        collection=mydoc.path.apply(lambda path: f"{path}/subdocs"),
        document_id="bitcoinkey",
        fields="{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}}}",
        project="my-project-name")
    sub_sub_document = gcp.firestore.Document("subSubDocument",
        collection=sub_document.path.apply(lambda path: f"{path}/subsubdocs"),
        document_id="asecret",
        fields="{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}",
        project="my-project-name")
    
    import * as pulumi from "@pulumi/pulumi";
    import * as gcp from "@pulumi/gcp";
    
    const mydoc = new gcp.firestore.Document("mydoc", {
        collection: "somenewcollection",
        documentId: "my-doc-id",
        fields: "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}",
        project: "my-project-name",
    });
    const subDocument = new gcp.firestore.Document("subDocument", {
        collection: pulumi.interpolate`${mydoc.path}/subdocs`,
        documentId: "bitcoinkey",
        fields: "{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}}}",
        project: "my-project-name",
    });
    const subSubDocument = new gcp.firestore.Document("subSubDocument", {
        collection: pulumi.interpolate`${subDocument.path}/subsubdocs`,
        documentId: "asecret",
        fields: "{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}",
        project: "my-project-name",
    });
    
    resources:
      mydoc:
        type: gcp:firestore:Document
        properties:
          collection: somenewcollection
          documentId: my-doc-id
          fields: '{"something":{"mapValue":{"fields":{"akey":{"stringValue":"avalue"}}}}}'
          project: my-project-name
      subDocument:
        type: gcp:firestore:Document
        properties:
          collection: ${mydoc.path}/subdocs
          documentId: bitcoinkey
          fields: '{"something":{"mapValue":{"fields":{"ayo":{"stringValue":"val2"}}}}}'
          project: my-project-name
      subSubDocument:
        type: gcp:firestore:Document
        properties:
          collection: ${subDocument.path}/subsubdocs
          documentId: asecret
          fields: '{"something":{"mapValue":{"fields":{"secret":{"stringValue":"hithere"}}}}}'
          project: my-project-name
    

    Create Document Resource

    new Document(name: string, args: DocumentArgs, opts?: CustomResourceOptions);
    @overload
    def Document(resource_name: str,
                 opts: Optional[ResourceOptions] = None,
                 collection: Optional[str] = None,
                 database: Optional[str] = None,
                 document_id: Optional[str] = None,
                 fields: Optional[str] = None,
                 project: Optional[str] = None)
    @overload
    def Document(resource_name: str,
                 args: DocumentArgs,
                 opts: Optional[ResourceOptions] = None)
    func NewDocument(ctx *Context, name string, args DocumentArgs, opts ...ResourceOption) (*Document, error)
    public Document(string name, DocumentArgs args, CustomResourceOptions? opts = null)
    public Document(String name, DocumentArgs args)
    public Document(String name, DocumentArgs args, CustomResourceOptions options)
    
    type: gcp:firestore:Document
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args DocumentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args DocumentArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args DocumentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args DocumentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args DocumentArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Document Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The Document resource accepts the following input properties:

    Collection string

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    DocumentId string

    The client-assigned document ID to use for this document during creation.


    Fields string

    The document's fields formated as a json string.

    Database string

    The Firestore database id. Defaults to "(default)".

    Project string

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    Collection string

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    DocumentId string

    The client-assigned document ID to use for this document during creation.


    Fields string

    The document's fields formated as a json string.

    Database string

    The Firestore database id. Defaults to "(default)".

    Project string

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    collection String

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    documentId String

    The client-assigned document ID to use for this document during creation.


    fields String

    The document's fields formated as a json string.

    database String

    The Firestore database id. Defaults to "(default)".

    project String

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    collection string

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    documentId string

    The client-assigned document ID to use for this document during creation.


    fields string

    The document's fields formated as a json string.

    database string

    The Firestore database id. Defaults to "(default)".

    project string

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    collection str

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    document_id str

    The client-assigned document ID to use for this document during creation.


    fields str

    The document's fields formated as a json string.

    database str

    The Firestore database id. Defaults to "(default)".

    project str

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    collection String

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    documentId String

    The client-assigned document ID to use for this document during creation.


    fields String

    The document's fields formated as a json string.

    database String

    The Firestore database id. Defaults to "(default)".

    project String

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the Document resource produces the following output properties:

    CreateTime string

    Creation timestamp in RFC3339 format.

    Id string

    The provider-assigned unique ID for this managed resource.

    Name string

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    Path string

    A relative path to the collection this document exists within

    UpdateTime string

    Last update timestamp in RFC3339 format.

    CreateTime string

    Creation timestamp in RFC3339 format.

    Id string

    The provider-assigned unique ID for this managed resource.

    Name string

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    Path string

    A relative path to the collection this document exists within

    UpdateTime string

    Last update timestamp in RFC3339 format.

    createTime String

    Creation timestamp in RFC3339 format.

    id String

    The provider-assigned unique ID for this managed resource.

    name String

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    path String

    A relative path to the collection this document exists within

    updateTime String

    Last update timestamp in RFC3339 format.

    createTime string

    Creation timestamp in RFC3339 format.

    id string

    The provider-assigned unique ID for this managed resource.

    name string

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    path string

    A relative path to the collection this document exists within

    updateTime string

    Last update timestamp in RFC3339 format.

    create_time str

    Creation timestamp in RFC3339 format.

    id str

    The provider-assigned unique ID for this managed resource.

    name str

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    path str

    A relative path to the collection this document exists within

    update_time str

    Last update timestamp in RFC3339 format.

    createTime String

    Creation timestamp in RFC3339 format.

    id String

    The provider-assigned unique ID for this managed resource.

    name String

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    path String

    A relative path to the collection this document exists within

    updateTime String

    Last update timestamp in RFC3339 format.

    Look up Existing Document Resource

    Get an existing Document resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: DocumentState, opts?: CustomResourceOptions): Document
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            collection: Optional[str] = None,
            create_time: Optional[str] = None,
            database: Optional[str] = None,
            document_id: Optional[str] = None,
            fields: Optional[str] = None,
            name: Optional[str] = None,
            path: Optional[str] = None,
            project: Optional[str] = None,
            update_time: Optional[str] = None) -> Document
    func GetDocument(ctx *Context, name string, id IDInput, state *DocumentState, opts ...ResourceOption) (*Document, error)
    public static Document Get(string name, Input<string> id, DocumentState? state, CustomResourceOptions? opts = null)
    public static Document get(String name, Output<String> id, DocumentState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Collection string

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    CreateTime string

    Creation timestamp in RFC3339 format.

    Database string

    The Firestore database id. Defaults to "(default)".

    DocumentId string

    The client-assigned document ID to use for this document during creation.


    Fields string

    The document's fields formated as a json string.

    Name string

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    Path string

    A relative path to the collection this document exists within

    Project string

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    UpdateTime string

    Last update timestamp in RFC3339 format.

    Collection string

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    CreateTime string

    Creation timestamp in RFC3339 format.

    Database string

    The Firestore database id. Defaults to "(default)".

    DocumentId string

    The client-assigned document ID to use for this document during creation.


    Fields string

    The document's fields formated as a json string.

    Name string

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    Path string

    A relative path to the collection this document exists within

    Project string

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    UpdateTime string

    Last update timestamp in RFC3339 format.

    collection String

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    createTime String

    Creation timestamp in RFC3339 format.

    database String

    The Firestore database id. Defaults to "(default)".

    documentId String

    The client-assigned document ID to use for this document during creation.


    fields String

    The document's fields formated as a json string.

    name String

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    path String

    A relative path to the collection this document exists within

    project String

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    updateTime String

    Last update timestamp in RFC3339 format.

    collection string

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    createTime string

    Creation timestamp in RFC3339 format.

    database string

    The Firestore database id. Defaults to "(default)".

    documentId string

    The client-assigned document ID to use for this document during creation.


    fields string

    The document's fields formated as a json string.

    name string

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    path string

    A relative path to the collection this document exists within

    project string

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    updateTime string

    Last update timestamp in RFC3339 format.

    collection str

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    create_time str

    Creation timestamp in RFC3339 format.

    database str

    The Firestore database id. Defaults to "(default)".

    document_id str

    The client-assigned document ID to use for this document during creation.


    fields str

    The document's fields formated as a json string.

    name str

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    path str

    A relative path to the collection this document exists within

    project str

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    update_time str

    Last update timestamp in RFC3339 format.

    collection String

    The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

    createTime String

    Creation timestamp in RFC3339 format.

    database String

    The Firestore database id. Defaults to "(default)".

    documentId String

    The client-assigned document ID to use for this document during creation.


    fields String

    The document's fields formated as a json string.

    name String

    A server defined name for this index. Format: projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}

    path String

    A relative path to the collection this document exists within

    project String

    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    updateTime String

    Last update timestamp in RFC3339 format.

    Import

    Document can be imported using any of these accepted formats:

     $ pulumi import gcp:firestore/document:Document default {{name}}
    

    Package Details

    Repository
    Google Cloud (GCP) Classic pulumi/pulumi-gcp
    License
    Apache-2.0
    Notes

    This Pulumi package is based on the google-beta Terraform Provider.

    gcp logo
    Google Cloud Classic v6.66.0 published on Monday, Sep 18, 2023 by Pulumi