Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

TTL creation for Firestore

As described here https://cloud.google.com/firestore/docs/ttl I have made an attempt to create a TTL policy for my entities in Firestore (Datastore mode). I get

.../collectionGroups/Session/fields/expireAt

In my Golang code I have that the Kind is named Session

datastore.NameKey("Session", "myid", nil)

is it then right to create a TTL with the following command?

gcloud firestore fields ttls update expireAt --project=<project> --database=<database> --disable-ttl --collection-group=Session

The documentation refers to collection-group BUT in datastore mode we have entity. I'm not sure whether the collection group is correct or not. I'm sure about the field because in the entity i have the field expireAt.

Solved Solved
0 4 905
1 ACCEPTED SOLUTION

Yes, you are correct. In Firestore's Datastore mode, the --collection-group flag corresponds to the "kind" parameter in your Datastore entities

View solution in original post

4 REPLIES 4

Hi Again @Salvo,

The command you have provided is correct syntax However it includes the --disable-ttl flag, which would disable the TTL policy for the specified field. 

Since you mentioned that you want to create a TTL policy, you should remove the --disable-ttl flag and provide the necessary information to define the TTL policy.

Here's an example of how you might create a TTL policy for the expireAt field in the Session collection group (or entity kind):

gcloud firestore fields ttls create expireAt --project=<project> --database=<database> --time-to-live=<time_to_live_duration> --collection-group=Session

 

Thanks @ms4446 for the reply.

Sorry that command is the result of wrong copy/paste from my side. I have used enable-ttl flag to enable the TTL policy.

What I wanted to double check with the community were the collection-group flag. If you confirm that it is correct and it must correspond to the kind parameter passed then all good. 

Thank you

Yes, you are correct. In Firestore's Datastore mode, the --collection-group flag corresponds to the "kind" parameter in your Datastore entities

Thanks for the confirmation.