-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcrud.txt
156 lines (107 loc) · 4.37 KB
/
crud.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
.. _crud:
=======================
MongoDB CRUD Operations
=======================
.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference
.. meta::
:description: Manage documents in collections by running create, read, update, and delete operations.
:keywords: atlas
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
CRUD operations *create*, *read*, *update*, and *delete*
:ref:`documents <bson-document-format>`.
You can connect with driver methods and perform CRUD operations
for deployments hosted in the following environments:
.. |page-topic| replace:: :atlas:`perform CRUD operations in the UI </atlas-ui/documents>`
.. cta-banner::
:url: https://www.mongodb.com/docs/atlas/atlas-ui/documents
:icon: Cloud
.. include:: /includes/fact-atlas-compatible.rst
Create Operations
-----------------
Create or insert operations add new :ref:`documents
<bson-document-format>` to a :ref:`collection <collections>`. If the
collection does not currently exist, insert operations will create the
collection.
MongoDB provides the following methods to insert documents into a
collection:
- :method:`db.collection.insertOne()`
- :method:`db.collection.insertMany()`
In MongoDB, insert operations target a single :term:`collection`. All
write operations in MongoDB are :doc:`atomic
</core/write-operations-atomicity>` on the level of a single
:ref:`document <bson-document-format>`.
.. include:: /images/crud-annotated-mongodb-insertOne.rst
For examples, see :doc:`/tutorial/insert-documents`.
.. _crud-read-operations:
Read Operations
---------------
Read operations retrieve :ref:`documents <bson-document-format>` from a
:ref:`collection <collections>`; i.e. query a collection for
documents. MongoDB provides the following methods to read documents from
a collection:
- :method:`db.collection.find()`
You can specify :ref:`query filters or criteria
<read-operations-query-argument>` that identify the documents to return.
.. include:: /images/crud-annotated-mongodb-find.rst
For examples, see:
- :doc:`/tutorial/query-documents`
- :doc:`/tutorial/query-embedded-documents`
- :doc:`/tutorial/query-arrays`
- :doc:`/tutorial/query-array-of-documents`
Update Operations
-----------------
Update operations modify existing :ref:`documents
<bson-document-format>` in a :ref:`collection <collections>`. MongoDB
provides the following methods to update documents of a collection:
- :method:`db.collection.updateOne()`
- :method:`db.collection.updateMany()`
- :method:`db.collection.replaceOne()`
In MongoDB, update operations target a single collection. All write
operations in MongoDB are :doc:`atomic
</core/write-operations-atomicity>` on the level of a single document.
You can specify criteria, or filters, that identify the documents to
update. These :ref:`filters <document-query-filter>` use the same
syntax as read operations.
.. include:: /images/crud-annotated-mongodb-updateMany.rst
For examples, see :doc:`/tutorial/update-documents`.
Delete Operations
-----------------
Delete operations remove documents from a collection. MongoDB provides
the following methods to delete documents of a collection:
- :method:`db.collection.deleteOne()`
- :method:`db.collection.deleteMany()`
In MongoDB, delete operations target a single :term:`collection`. All
write operations in MongoDB are :doc:`atomic
</core/write-operations-atomicity>` on the level of a single document.
You can specify criteria, or filters, that identify the documents to
remove. These :ref:`filters <document-query-filter>` use the same
syntax as read operations.
.. include:: /images/crud-annotated-mongodb-deleteMany.rst
For examples, see :doc:`/tutorial/remove-documents`.
Bulk Write
----------
MongoDB provides the ability to perform write operations in bulk. For
details, see :doc:`/core/bulk-write-operations`.
.. toctree::
:titlesonly:
:hidden:
Insert </tutorial/insert-documents>
Query </tutorial/query-documents>
Update </tutorial/update-documents>
Remove </tutorial/remove-documents>
Bulk Write </core/bulk-write-operations>
Retryable Writes </core/retryable-writes>
Retryable Reads </core/retryable-reads>
SQL to MongoDB </reference/sql-comparison>
Text Search </text-search>
Geospatial Queries </geospatial-queries>
Read Concern </reference/read-concern>
Write Concern </reference/write-concern>
CRUD Concepts </core/crud>