Skip to content

Commit 2f8c397

Browse files
docs(firestore): update guide for advance usage
1 parent 4435154 commit 2f8c397

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

docs/guide/firestore.rst

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ the collection named ``Movies``, use ``set()`` method.
4040
"lead": {
4141
"name": "Robert Downey Jr."
4242
},
43+
'cast': ['Gwyneth Paltrow']
4344
'released': False,
45+
'prequel': None
4446
}
4547
4648
fsdb.collection('Marvels').document('Movies').set(data)
@@ -61,6 +63,8 @@ To read data from an existing document of an collection, use ``get()`` method.
6163
fsdb.collection('Marvels').document('Movies').get()
6264
..
6365
66+
67+
6468
It is possible to filter the data of an document to receive specific fields.
6569

6670
.. code-block:: python
@@ -76,8 +80,7 @@ It is possible to filter the data of an document to receive specific fields.
7680
Update Data
7781
-----------
7882

79-
To update existing data or add more data to an existing document, use
80-
``update()`` method.
83+
To add more data to an existing document, use ``update()`` method.
8184

8285
.. code-block:: python
8386
@@ -90,6 +93,10 @@ To update existing data or add more data to an existing document, use
9093
fsdb.collection('Marvels').document('Movies').update(data)
9194
..
9295
96+
97+
98+
To update existing data to an existing document, use ``update()`` method.
99+
93100
.. code-block:: python
94101
95102
# update data of an existing document
@@ -102,9 +109,53 @@ To update existing data or add more data to an existing document, use
102109
..
103110
104111

112+
113+
To add an item to an array field in an existing document, use
114+
``update()`` method.
115+
116+
.. code-block:: python
117+
118+
from google.cloud.firestore import ArrayUnion
119+
data = {
120+
'cast': ArrayUnion(['Terrence Howard'])
121+
}
122+
123+
fsdb.collection('Marvels').document('Movies').update(data)
124+
..
125+
126+
105127
Delete Data
106128
-----------
107129

130+
To remove an field from an existing document, use ``update()`` method.
131+
132+
.. code-block:: python
133+
134+
from google.cloud.firestore import DELETE_FIELD
135+
data = {
136+
'prequel': DELETE_FIELD
137+
}
138+
139+
fsdb.collection('Marvels').document('Movies').update(data)
140+
..
141+
142+
143+
144+
To remove an item to an array field in an existing document, use
145+
``update()`` method.
146+
147+
.. code-block:: python
148+
149+
from google.cloud.firestore import ArrayRemove
150+
data = {
151+
'cast': ArrayRemove(['Terrence Howard'])
152+
}
153+
154+
fsdb.collection('Marvels').document('Movies').update(data)
155+
..
156+
157+
158+
108159
To remove an existing document in a collection, use ``delete()``
109160
method.
110161

0 commit comments

Comments
 (0)