Skip to content

Commit 90b14e4

Browse files
JU-2094joehan
andauthored
Update README for TTL Policy (#6647)
* Update README for TTL Policy * Update README for TTL policy. --------- Co-authored-by: joehan <joehanley@google.com>
1 parent 36311ea commit 90b14e4

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/firestore/README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ The schema for one object in the `fieldOverrides` array is as follows. Optional
6161

6262
Note that Cloud Firestore document fields can only be indexed in one [mode](https://firebase.google.com/docs/firestore/query-data/index-overview#index_modes), thus a field object cannot contain both the `order` and `arrayConfig` properties.
6363

64-
For more information about time-to-live (TTL) policies review the [official documentation](https://cloud.google.com/firestore/docs/ttl).
65-
6664
```javascript
6765
collectionGroup: string // Labeled "Collection ID" in the Firebase console
6866
fieldPath: string
@@ -72,3 +70,41 @@ For more information about time-to-live (TTL) policies review the [official docu
7270
order?: string // One of "ASCENDING", "DESCENDING"; excludes arrayConfig property
7371
arrayConfig?: string // If this parameter used, must be "CONTAINS"; excludes order property
7472
```
73+
74+
#### TTL Policy
75+
76+
A TTL policy can be enabled or disabled using the `fieldOverrides` array as it follows:
77+
78+
```javascript
79+
// Optional, disable index single-field collection group indexes
80+
fieldOverrides: [
81+
{
82+
collectionGroup: "posts",
83+
fieldPath: "ttlField",
84+
ttl: "true", // Explicitly enable TTL on this Field.
85+
// Disable indexing so empty the indexes array
86+
indexes: [],
87+
},
88+
];
89+
```
90+
91+
To keep the default indexing in the field and enable a TTL policy:
92+
93+
```javascript
94+
{
95+
"fieldOverrides": [
96+
{
97+
"collectionGroup": "yourCollectionGroup",
98+
"fieldPath": "yourFieldPath",
99+
"ttl": true,
100+
"indexes": [
101+
{ "order": "ASCENDING", "queryScope": "COLLECTION_GROUP" },
102+
{ "order": "DESCENDING", "queryScope": "COLLECTION_GROUP" },
103+
{ "arrayConfig": "CONTAINS", "queryScope": "COLLECTION_GROUP" }
104+
]
105+
}
106+
]
107+
}
108+
```
109+
110+
For more information about time-to-live (TTL) policies review the [official documentation](https://cloud.google.com/firestore/docs/ttl).

0 commit comments

Comments
 (0)