44Write Data to MongoDB
55=====================
66
7+ .. contents:: On this page
8+ :local:
9+ :backlinks: none
10+ :depth: 2
11+ :class: singlecol
12+
13+ .. facet::
14+ :name: genre
15+ :values: reference
16+
717.. meta::
818 :description: Learn how to use {+driver-short+} to write data to MongoDB.
19+ :keywords: usage examples, save, crud, create, code example
920
1021.. toctree::
1122 :titlesonly:
@@ -18,9 +29,124 @@ Write Data to MongoDB
1829 /write/bulk-write
1930 /write/gridfs
2031
21- - :ref:`pymongo-write-insert`
22- - :ref:`pymongo-write-update`
23- - :ref:`pymongo-write-replace`
24- - :ref:`pymongo-write-delete`
25- - :ref:`pymongo-bulk-write`
26- - :ref:`pymongo-gridfs`
32+ Overview
33+ --------
34+
35+ On this page, you can see copyable code examples that show common
36+ methods you can use to write data to MongoDB with {+driver-short+}.
37+
38+ .. tip::
39+
40+ To learn more about any of the methods shown on this page, see the link
41+ provided in each section.
42+
43+ To use an example from this page, copy the code example into the
44+ :ref:`sample application <pymongo-write-sample>` or your own application.
45+ Be sure to replace all placeholders in the code examples, such as ``<connection string URI>``, with
46+ the relevant values for your MongoDB deployment.
47+
48+ .. _pymongo-write-sample:
49+
50+ .. include:: /includes/usage-examples/sample-app-intro.rst
51+
52+ .. literalinclude:: /includes/usage-examples/sample-app.py
53+ :language: python
54+ :copyable:
55+ :linenos:
56+ :emphasize-lines: 11-13
57+
58+ Insert One
59+ ----------
60+
61+ .. literalinclude:: /includes/usage-examples/write-code-examples.py
62+ :start-after: start-insert-one
63+ :end-before: end-insert-one
64+ :language: python
65+ :copyable:
66+
67+ To learn more about the ``insert_one()`` method, see the :ref:`Insert Documents
68+ <pymongo-write-insert>` guide.
69+
70+ Insert Multiple
71+ ---------------
72+
73+ .. literalinclude:: /includes/usage-examples/write-code-examples.py
74+ :start-after: start-insert-multiple
75+ :end-before: end-insert-multiple
76+ :language: python
77+ :copyable:
78+
79+ To learn more about the ``insert_many()`` method, see the :ref:`Insert Documents
80+ <pymongo-write-insert>` guide.
81+
82+ Update One
83+ ----------
84+
85+ .. literalinclude:: /includes/usage-examples/write-code-examples.py
86+ :start-after: start-update-one
87+ :end-before: end-update-one
88+ :language: python
89+ :copyable:
90+
91+ To learn more about the ``update_one()`` method, see the
92+ :ref:`Update Documents <pymongo-write-update>` guide.
93+
94+ Update Multiple
95+ ---------------
96+
97+ .. literalinclude:: /includes/usage-examples/write-code-examples.py
98+ :start-after: start-update-multiple
99+ :end-before: end-update-multiple
100+ :language: python
101+ :copyable:
102+
103+ To learn more about the ``update_many()`` method, see the
104+ :ref:`Update Documents <pymongo-write-update>` guide.
105+
106+ Replace One
107+ -----------
108+
109+ .. literalinclude:: /includes/usage-examples/write-code-examples.py
110+ :start-after: start-replace-one
111+ :end-before: end-replace-one
112+ :language: python
113+ :copyable:
114+
115+ To learn more about the ``replace_one()`` method, see the
116+ :ref:`Replace Documents <pymongo-write-replace>` guide.
117+
118+ Delete One
119+ ----------
120+
121+ .. literalinclude:: /includes/usage-examples/write-code-examples.py
122+ :start-after: start-delete-one
123+ :end-before: end-delete-one
124+ :language: python
125+ :copyable:
126+
127+ To learn more about the ``delete_one()`` method, see the
128+ :ref:`Delete Documents <pymongo-write-delete>` guide.
129+
130+ Delete Multiple
131+ ---------------
132+
133+ .. literalinclude:: /includes/usage-examples/write-code-examples.py
134+ :start-after: start-delete-multiple
135+ :end-before: end-delete-multiple
136+ :language: python
137+ :copyable:
138+
139+ To learn more about the ``delete_many()`` method, see the
140+ :ref:`Delete Documents <pymongo-write-delete>` guide.
141+
142+ Bulk Write
143+ ----------
144+
145+ .. literalinclude:: /includes/usage-examples/write-code-examples.py
146+ :start-after: start-bulk-write
147+ :end-before: end-bulk-write
148+ :language: python
149+ :copyable:
150+
151+ To learn more about the ``bulk_write()`` method, see the
152+ :ref:`Bulk Write <pymongo-bulk-write>` guide.
0 commit comments