Skip to content

Commit b0b57fb

Browse files
(DOCSP-6532): Insert documents in JSON Mode
1 parent c3877f7 commit b0b57fb

12 files changed

+113
-88
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ help: ## Show this help message
1818
@echo 'Variables'
1919
@printf " \033[36m%-18s\033[0m %s\n" 'ARGS' 'Arguments to pass to mut-publish'
2020

21-
html: migrate-assets ## Builds this branch's HTML under build/<branch>/html
21+
html: ## Builds this branch's HTML under build/<branch>/html
2222
giza make html
2323

2424
## Builds this branch's HTML under build/<branch>/html
25-
clean-html: migrate-assets
25+
clean-html:
2626
rm -rf build/${GIT_BRANCH}
2727
giza make html
2828

29-
publish: migrate-assets ## Builds this branch's publishable HTML and other artifacts under build/public
29+
publish: ## Builds this branch's publishable HTML and other artifacts under build/public
3030
giza make publish
3131
if [ ${GIT_BRANCH} = master ]; then mut-redirects config/redirects -o build/public/.htaccess; fi
3232

source/documents/insert.txt

Lines changed: 89 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,46 @@ Insert Documents
1212
:depth: 1
1313
:class: singlecol
1414

15-
Click the :guilabel:`Insert Document` button to insert a new document:
15+
.. important::
1616

17-
.. figure:: /images/compass/insert-button.png
18-
:figwidth: 816px
17+
Inserting documents is not permitted in
18+
:guilabel:`MongoDB Compass Readonly Edition`.
1919

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.
2122

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.
2426

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.
2731

28-
.. figure:: /images/compass/insert-document2.png
29-
:figwidth: 627px
32+
Procedure
33+
---------
3034

31-
.. tip::
35+
To insert documents into your collection:
3236

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`.
3539

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
3842

39-
.. code-block:: javascript
43+
2. Select the appropriate view based on how you would like to
44+
insert documents.
4045

41-
[ "first", "second", 3 ]
46+
- Click the ``{ }`` brackets for JSON view. This is the default
47+
view.
4248

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.
4750

48-
.. code-block:: javascript
51+
|
4952

50-
{
51-
"email": "[email protected]",
52-
"phone": "555-555-1212"
53-
}
53+
.. figure:: /images/compass/insert-document-view-select.png
54+
:figwidth: 590px
5455

5556
Limitation
5657
----------
@@ -61,35 +62,74 @@ to a :atlas:`Data Lake </data-lake>`.
6162
Add New Fields
6263
--------------
6364

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::
6766

68-
.. figure:: /images/compass/insert-document-new-field.svg
69-
:figwidth: 621px
67+
.. tab:: JSON View
68+
:tabid: json
7069

71-
You can also add a new field at the end by clicking the Tab from the
72-
value of the last field.
70+
|
7371

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.
7575

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::
8077

81-
Change Field Type
82-
-----------------
78+
The following array inserts 5 documents into
79+
the collection:
8380

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
8682

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+
]
8990

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`.
9392

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`.

source/documents/modify.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Modify Documents
66

77
.. default-domain:: mongodb
88

9+
You can edit existing documents in your collection. When you edit
10+
a document, |compass-short| performs a
11+
:manual:`findAndModify </reference/method/db.collection.findAndModify/>`
12+
operation to update the document.
13+
914
Select the appropriate tab based on whether you are viewing your
1015
documents in List, JSON, or Table view:
1116

@@ -72,9 +77,11 @@ documents in List, JSON, or Table view:
7277
.. figure:: /images/compass/update-field.png
7378
:figwidth: 740px
7479

80+
Save Changes
81+
------------
82+
7583
When you are finished editing the document, click the ``Update``
76-
button to commit your changes. Compass performs a
77-
``findAndModify`` operation to update the document.
84+
button to commit your changes.
7885

7986
Revert a Change
8087
---------------
@@ -98,6 +105,10 @@ documents in List, JSON, or Table view:
98105
You can now add, remove, and edit field values by modifying
99106
the JSON document.
100107

108+
By default, embedded objects and arrays are hidden. To expand
109+
these values, click the field arrow.
110+
111+
101112
.. tab:: Table View
102113
:tabid: table-view
103114

@@ -134,6 +145,10 @@ documents in List, JSON, or Table view:
134145

135146
#. Click :guilabel:`Add Field after <Field Name>`.
136147

148+
#. Populate your newly created field.
149+
150+
#. Click :guilabel:`Update` to confirm your changes.
151+
137152
Revert a Change
138153
---------------
139154

27.8 KB
Loading
503 KB
Loading

source/images/compass/insert-document-new-field.svg

Lines changed: 0 additions & 17 deletions
This file was deleted.
24 KB
Loading
14.4 KB
Loading
5.8 KB
Loading
14.1 KB
Loading

0 commit comments

Comments
 (0)