Skip to content

Commit b1af488

Browse files
docs(firestore): add CRUD operation guide
1 parent ac0c3ac commit b1af488

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

docs/guide/firebase-rest-api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ A Firebase app can use multiple Firebase services.
126126

127127
``firebaseApp.database()`` - :ref:`Database<guide/database:Database>`
128128

129+
``firebaseApp.firestore()`` - :ref:`Firestore<guide/firestore:Firestore>`
130+
129131
``firebaseApp.storage()`` - :ref:`Storage<guide/storage:Storage>`
130132

131133
Check out the documentation for each service for further details.

docs/guide/firestore.rst

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Firestore
2+
=========
3+
4+
The firestore service allows you to run CRUD operations to your Firebase Firestore
5+
Database.
6+
7+
.. code-block:: python
8+
9+
# Create database instance
10+
fsdb = firebaseApp.firestore()
11+
..
12+
13+
.. note::
14+
Each of the following methods accepts a user token:
15+
:ref:`get()<guide/firestore:get>`, :ref:`set()<guide/firestore:set>`,
16+
:ref:`update()<guide/firestore:update>`, and
17+
:ref:`delete()<guide/firestore:delete>`.
18+
19+
20+
Build Path
21+
----------
22+
23+
You can build paths to your data by using the ``collection()`` and ``document()`` method.
24+
25+
.. code-block:: python
26+
27+
fsdb.collection('Marvels').document('Movies')
28+
fsdb.collection('Marvels').document('Movies').collection('PhaseOne').document('2008')
29+
30+
..
31+
32+
Save Data
33+
---------
34+
35+
set
36+
^^^
37+
38+
To store data in a collection named ``Marvels`` and a document inside
39+
the collection named ``Movies``, use ``set()`` method.
40+
41+
.. code-block:: python
42+
43+
data = {
44+
"name": "Iron Man",
45+
"lead": {
46+
"name": "Robert Downey Jr."
47+
},
48+
'released': False,
49+
}
50+
51+
fsdb.collection('Marvels').document('Movies').set(data)
52+
..
53+
54+
.. attention::
55+
Using this method on an existing document will overwrite the existing
56+
document.
57+
58+
59+
Read Data
60+
---------
61+
62+
get
63+
^^^
64+
65+
To read data from an existing document of an collection, use ``get()`` method.
66+
67+
.. code-block:: python
68+
69+
fsdb.collection('Marvels').document('Movies').get()
70+
..
71+
72+
It is possible to filter the data of an document to receive specific fields.
73+
74+
.. code-block:: python
75+
76+
fsdb.collection('Marvels').document('Movies').get(field_paths=['lead.name', 'released'])
77+
78+
# Output:
79+
# {'lead': {'name': "Robert Downey Jr."}, 'released': False}
80+
..
81+
82+
83+
84+
Update Data
85+
-----------
86+
87+
update
88+
^^^^^^
89+
90+
To update existing data or add more data to an existing document, use
91+
``update()`` method.
92+
93+
.. code-block:: python
94+
95+
# add new data to an existing document
96+
97+
data = {
98+
'year': 2008,
99+
}
100+
101+
fsdb.collection('Marvels').document('Movies').update(data)
102+
..
103+
104+
.. code-block:: python
105+
106+
# update data of an existing document
107+
108+
data = {
109+
'released': True,
110+
}
111+
112+
fsdb.collection('Marvels').document('Movies').update(data)
113+
..
114+
115+
116+
Delete Data
117+
-----------
118+
119+
delete
120+
^^^^^^
121+
122+
To remove an existing document in a collection, use ``delete()``
123+
method.
124+
125+
.. code-block:: python
126+
127+
fsdb.collection('Marvels').document('Movies').delete()
128+
..

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Documentation contents
103103
guide/firebase-rest-api
104104
guide/authentication
105105
guide/database
106+
guide/firestore
106107
guide/storage
107108

108109
.. toctree::

0 commit comments

Comments
 (0)