@@ -12,45 +12,46 @@ Insert Documents
12
12
:depth: 1
13
13
:class: singlecol
14
14
15
- Click the :guilabel:`Insert Document` button to insert a new document :
15
+ .. important: :
16
16
17
- .. figure:: /images/compass/insert-button.png
18
- :figwidth: 816px
17
+ Inserting documents is not permitted in
18
+ :guilabel:`MongoDB Compass Readonly Edition`.
19
19
20
- The insert dialog appears:
20
+ |compass-short| provides two ways to insert documents into your
21
+ collections: JSON Mode and a Field-by-Field Editor.
21
22
22
- .. figure:: /images/compass/insert-document.png
23
- :figwidth: 598px
23
+ JSON Mode
24
+ Allows you to write or paste JSON documents in the editor. Use
25
+ this mode to insert multiple documents at once as an array.
24
26
25
- For each field in the document, select field type and fill in the
26
- field name and value.
27
+ Field-by-Field Editor
28
+ Provides a more interactive experience to create documents, allowing
29
+ you to select individual field values and types. This mode only
30
+ supports inserting one document at a time.
27
31
28
- .. figure:: /images/compass/insert-document2.png
29
- :figwidth: 627px
32
+ Procedure
33
+ ---------
30
34
31
- .. tip: :
35
+ To insert documents into your collection :
32
36
33
- For the field values, you can paste valid JSON that can be parsed by
34
- JavaScript's ``JSON.parse` `.
37
+ 1. Click the :guilabel:`Add Data` dropdown and select
38
+ :guilabel:`Insert Document `.
35
39
36
- - If the pasted JSON is an Array, the first character must be a left
37
- bracket ``[`` and the last character must be a right bracket ``]``:
40
+ .. figure:: /images/compass/insert-button.png
41
+ :figwidth: 590px
38
42
39
- .. code-block:: javascript
43
+ 2. Select the appropriate view based on how you would like to
44
+ insert documents.
40
45
41
- [ "first", "second", 3 ]
46
+ - Click the ``{ }`` brackets for JSON view. This is the default
47
+ view.
42
48
43
- - If the pasted JSON is an Object (i.e. a document), the keys must
44
- be quoted in double quotes and are permitted to be escaped. The
45
- first character must be left curly brace ``{`` and the last must
46
- be right curly brace ``}``:
49
+ - Click the list icon for Field-by-Field mode.
47
50
48
- .. code-block:: javascript
51
+ |
49
52
50
- {
51
-
52
- "phone": "555-555-1212"
53
- }
53
+ .. figure:: /images/compass/insert-document-view-select.png
54
+ :figwidth: 590px
54
55
55
56
Limitation
56
57
----------
@@ -61,35 +62,74 @@ to a :atlas:`Data Lake </data-lake>`.
61
62
Add New Fields
62
63
--------------
63
64
64
- To add a new field for the document, hover over the row number in the
65
- dialog (the row number is not part of the document but the dialog
66
- display) and click on the plus sign add a new field after the field.
65
+ .. tabs::
67
66
68
- .. figure :: /images/compass/insert-document-new-field.svg
69
- :figwidth: 621px
67
+ .. tab :: JSON View
68
+ :tabid: json
70
69
71
- You can also add a new field at the end by clicking the Tab from the
72
- value of the last field.
70
+ |
73
71
74
- .. tip::
72
+ 3. In JSON format, type or paste the document(s) you want to
73
+ insert into the collection. To insert multiple documents,
74
+ enter a comma-separated array of JSON documents.
75
75
76
- To add a new field after an array or a document field, hover over
77
- the row number in the dialog (the row number is not part of the
78
- document but the dialog display) and click on the plus sign add a
79
- new field after the field.
76
+ .. example::
80
77
81
- Change Field Type
82
- -----------------
78
+ The following array inserts 5 documents into
79
+ the collection:
83
80
84
- You can change the data type of a field by using the data type
85
- selectors on the right of the field.
81
+ .. code-block:: json
86
82
87
- .. figure:: /images/compass/insert-document3.png
88
- :figwidth: 644px
83
+ [
84
+ { "_id" : 8752, "title" : "Divine Comedy", "author" : "Dante", "copies" : 1 },
85
+ { "_id" : 7000, "title" : "The Odyssey", "author" : "Homer", "copies" : 10 },
86
+ { "_id" : 7020, "title" : "Iliad", "author" : "Homer", "copies" : 10 },
87
+ { "_id" : 8645, "title" : "Eclogues", "author" : "Dante", "copies" : 2 },
88
+ { "_id" : 8751, "title" : "The Banquet", "author" : "Dante", "copies" : 2 }
89
+ ]
89
90
90
- To change the ``_id`` field to use a custom value, change
91
- the data type from ``ObjectID`` to ``string`` and then overwrite the
92
- ``_id`` value:
91
+ 4. Click :guilabel:`Insert`.
93
92
94
- .. figure:: /images/compass/insert-document4.png
95
- :figwidth: 626px
93
+ .. tab:: Field-by-Field Editor
94
+ :tabid: field-by-field
95
+
96
+ |
97
+
98
+ 3. For each field in the document, select field type and fill
99
+ in the field name and value.
100
+
101
+ .. figure:: /images/compass/insert-document2.png
102
+ :figwidth: 590px
103
+
104
+ Add New Fields
105
+ ~~~~~~~~~~~~~~
106
+
107
+ To add a new field in the document, hover over the row number
108
+ in the dialog (the row number is not part of the document but
109
+ the dialog display) and click the :icon-fa5:`plus` icon to
110
+ add a new field after the selected row.
111
+
112
+ You can also add a new field at the end of the document by
113
+ pressing the tab key when your text cursor is in the value of
114
+ the last document field.
115
+
116
+ .. figure:: /images/compass/insert-document-new-field.png
117
+ :figwidth: 590px
118
+
119
+ Change Field Type
120
+ ~~~~~~~~~~~~~~~~~
121
+
122
+ You can change the data type of a field by using the data
123
+ type selectors on the right of the field.
124
+
125
+ .. figure:: /images/compass/insert-document3.png
126
+ :figwidth: 590px
127
+
128
+ To change the ``_id`` field to use a custom value, change the
129
+ data type from ``ObjectID`` to ``string`` and then overwrite
130
+ the ``_id`` value:
131
+
132
+ .. figure:: /images/compass/insert-document4.png
133
+ :figwidth: 590px
134
+
135
+ 4. Click :guilabel:`Insert`.
0 commit comments