Skip to content

Commit f531137

Browse files
jeff-allen-mongokay-kim
authored andcommitted
DOCSP-1376 - Integrating compass into insert docs page
1 parent 3263031 commit f531137

File tree

6 files changed

+134
-16
lines changed

6 files changed

+134
-16
lines changed
33.3 KB
Loading
Loading
29.5 KB
Loading

source/includes/driver-example-insert-1.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
db.inventory.insertOne(
1010
{ item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } }
1111
)
12-
12+
1313
.. only:: website
1414

1515
You can run the operation in the web shell below:
1616

1717
.. include:: /includes/fact-mws.rst
1818

19+
- id: compass
20+
content: |
21+
.. figure:: /images/compass-insert-document-inventory.png
22+
1923
- id: python
2024
content: |
2125
.. class:: copyable-code

source/includes/driver-example-insert-2.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
99
db.inventory.find( { item: "canvas" } )
1010
11+
- id: compass
12+
content: |
13+
.. figure:: /images/compass-query-collection.png
14+
15+
Specify a filter in the MongoDB Compass query bar and click
16+
:guilabel:`Find` to execute the query.
17+
18+
The above filter specifies that MongoDB Compass only return
19+
documents where the ``item`` field is equal to ``canvas``.
20+
21+
For more information on the MongoDB Compass Query Bar, see the
22+
Compass
23+
`Query Bar <https://docs.mongodb.com/compass/master/query-bar/>`_
24+
documentation.
25+
1126
- id: python
1227
content: |
1328
.. class:: copyable-code

source/tutorial/insert-documents.txt

Lines changed: 114 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ Insert a Single Document
4242
ObjectId value to the new document. See
4343
:ref:`write-op-insert-behavior`.
4444

45+
- id: compass
46+
content: |
47+
To insert a single document using :ref:`MongoDB Compass <compass-index>`:
48+
49+
1. Navigate to the collection you wish to insert the document
50+
into:
51+
52+
a. In the left-hand MongoDB Compass navigation pane, click
53+
the database to which your target collection belongs.
54+
55+
b. From the database view, click the target collection name.
56+
57+
2. Click the :guilabel:`Insert Document` button:
58+
59+
.. figure:: /images/compass-insert-button.png
60+
61+
3. For each field in the document, select the field type and
62+
fill in the field name and value. Add fields by clicking
63+
the last line number, then clicking
64+
:guilabel:`Add Field After ...`
65+
66+
- For ``Object`` types, add nested fields by clicking the
67+
last field's number and selecting
68+
:guilabel:`Add Field After ...`
69+
70+
- For ``Array`` types, add additional elements to the array
71+
by clicking the last element's line number and selecting
72+
:guilabel:`Add Array Element After ...`
73+
74+
4. Once all fields have been filled out, click :guilabel:`Insert`.
75+
76+
The following example inserts a new document into the
77+
``test.inventory`` collection:
78+
4579
- id: python
4680
content: |
4781
:py:meth:`pymongo.collection.Collection.insert_one` inserts a
@@ -75,7 +109,7 @@ Insert a Single Document
75109

76110
.. code-block:: json
77111

78-
{ item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } }
112+
{ item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } }
79113

80114
The following example inserts the document above into the
81115
``inventory`` collection. If the document does not specify
@@ -124,13 +158,13 @@ Insert a Single Document
124158
:ruby-api:`Mongo::Collection#insert_one()<Collection.html#insert_one-instance_method>`
125159
inserts a *single* :ref:`document<bson-document-format>` into a
126160
collection.
127-
161+
128162
The following example inserts a new document into the
129163
``inventory`` collection. If the document does not specify
130164
an ``_id`` field, the Ruby driver adds the ``_id`` field
131165
with an ObjectId value to the new document. See
132166
:ref:`write-op-insert-behavior`.
133-
167+
134168
- id: scala
135169
content: |
136170
:scala-api:`collection.insertOne()<insertOne(document:TResult,options:org.mongodb.scala.model.InsertOneOptions):org.mongodb.scala.SingleObservable[org.mongodb.scala.Completed]>`
@@ -167,6 +201,20 @@ Insert a Single Document
167201
an example of a return document, see
168202
:ref:`db.collection.insertOne() reference<insertOne-examples>`.
169203

204+
- id: compass
205+
content: |
206+
.. note::
207+
208+
MongoDB Compass generates the ``_id`` field and its value
209+
automatically. The generated
210+
:term:`ObjectId` consists of a
211+
unique randomly generated hexadecimal value.
212+
213+
You can change this value prior to inserting your document
214+
so long as it remains unique and is a valid ``ObjectId``.
215+
For more information on the ``_id`` field, see
216+
:ref:`_id Field <insert-id-field>`.
217+
170218
- id: python
171219
content: |
172220
:py:meth:`~pymongo.collection.Collection.insert_one` returns an
@@ -179,7 +227,7 @@ Insert a Single Document
179227

180228
- id: java-async
181229
content: |
182-
`com.mongodb.reactivestreams.client.MongoCollection.insertOne <http://mongodb.github.io/mongo-java-driver-reactivestreams/1.6/javadoc/com/mongodb/reactivestreams/client/MongoCollection.html#insertOne(TDocument)>`_
230+
`com.mongodb.reactivestreams.client.MongoCollection.insertOne <http://mongodb.github.io/mongo-java-driver-reactivestreams/1.6/javadoc/com/mongodb/reactivestreams/client/MongoCollection.html#insertOne(TDocument)>`_
183231
returns a `Publisher <http://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/org/reactivestreams/Publisher.html>`_
184232
object. The ``Publisher`` inserts the document into a collection when subscribers request data.
185233

@@ -210,7 +258,7 @@ Insert a Single Document
210258

211259
- id: ruby
212260
content: |
213-
Upon successful insert, the
261+
Upon successful insert, the
214262
:ruby-api:`insert_one()<Collection.html#insert_one-instance_method>`
215263
method returns an instance of
216264
:ruby-api:`Mongo::Operation::Result<Operation/Result.html>`, whose
@@ -219,7 +267,7 @@ Insert a Single Document
219267

220268
- id: scala
221269
content: |
222-
Upon successful insert, the
270+
Upon successful insert, the
223271
:scala-api:`collection.insertOne()<MongoCollection.html#insertOne(document:TResult,options:org.mongodb.scala.model.InsertOneOptions):org.mongodb.scala.SingleObservable[org.mongodb.scala.Completed]>`
224272
method returns an instance of
225273
:scala-api:`collection.insertOne().results();<InsertOneResult>` whose
@@ -239,13 +287,13 @@ To retrieve the document that you just inserted, :ref:`query the collection
239287
Insert Multiple Documents
240288
-------------------------
241289

242-
.. versionadded:: 3.2
243-
244290
.. tabs-drivers::
245291

246292
tabs:
247293
- id: shell
248294
content: |
295+
.. versionadded:: 3.2
296+
249297
:method:`db.collection.insertMany()` can insert *multiple*
250298
:ref:`documents <bson-document-format>` into a collection. Pass an
251299
array of documents to the method.
@@ -255,8 +303,15 @@ Insert Multiple Documents
255303
``_id`` field, MongoDB adds the ``_id`` field with an ObjectId
256304
value to each document. See :ref:`write-op-insert-behavior`.
257305

306+
- id: compass
307+
content: |
308+
Currently, MongoDB Compass does not support inserting multiple
309+
documents in a single operation.
310+
258311
- id: python
259312
content: |
313+
.. versionadded:: 3.2
314+
260315
:py:meth:`pymongo.collection.Collection.insert_many` can insert
261316
*multiple* :ref:`documents <bson-document-format>` into a
262317
collection. Pass an iterable of documents to the method.
@@ -268,6 +323,8 @@ Insert Multiple Documents
268323

269324
- id: java-sync
270325
content: |
326+
.. versionadded:: 3.2
327+
271328
com.mongodb.client.MongoCollection.insertMany_
272329
can insert *multiple* :ref:`documents <bson-document-format>`
273330
into a collection. Pass a list of documents to the method.
@@ -279,11 +336,12 @@ Insert Multiple Documents
279336

280337
- id: java-async
281338
content: |
339+
.. versionadded:: 3.2
282340

283341
`com.mongodb.reactivestreams.client.MongoCollection.html.insertMany
284342
<http://mongodb.github.io/mongo-java-driver-reactivestreams/1.6/javadoc/com/mongodb/reactivestreams/client/MongoCollection.html#insertMany(java.util.List)>`_
285343
inserts the following documents with the `Java Reactive Streams
286-
Driver <http://mongodb.github.io/mongo-java-driver-reactivestreams/1.6/>`_:
344+
Driver <http://mongodb.github.io/mongo-java-driver-reactivestreams/1.6/>`_:
287345

288346
.. code-block:: json
289347

@@ -298,6 +356,8 @@ Insert Multiple Documents
298356

299357
- id: nodejs
300358
content: |
359+
.. versionadded:: 3.2
360+
301361
:node-api:`Collection.insertMany() <Collection.html#insertMany>`
302362
can insert *multiple* :ref:`documents <bson-document-format>`
303363
into a collection. Pass an array of documents to the method.
@@ -310,6 +370,8 @@ Insert Multiple Documents
310370

311371
- id: php
312372
content: |
373+
.. versionadded:: 3.2
374+
313375
:phpmethod:`MongoDB\\Collection::insertMany() <phpmethod.MongoDB\\Collection::insertMany>`
314376
can insert *multiple* :ref:`documents <bson-document-format>` into a
315377
collection. Pass an array of documents to the method.
@@ -321,6 +383,8 @@ Insert Multiple Documents
321383

322384
- id: perl
323385
content: |
386+
.. versionadded:: 3.2
387+
324388
:perl-api:`MongoDB::Collection::insert_many()<Collection#insert_many>`
325389
can insert *multiple* :ref:`documents <bson-document-format>` into a
326390
collection. Pass an array reference of documents to the method.
@@ -332,6 +396,8 @@ Insert Multiple Documents
332396

333397
- id: ruby
334398
content: |
399+
.. versionadded:: 3.2
400+
335401
:ruby-api:`Mongo::Collection#insert_many()<Collection.html#insert_many-instance_method>`
336402
can insert *multiple* :ref:`documents <bson-document-format>` into a
337403
collection. Pass an array of documents to the method.
@@ -343,17 +409,21 @@ Insert Multiple Documents
343409

344410
- id: scala
345411
content: |
412+
.. versionadded:: 3.2
413+
346414
:scala-api:`collection.insertMany()<insertMany(documents:Seq[_<:TResult],options:org.mongodb.scala.model.InsertManyOptions):org.mongodb.scala.SingleObservable[org.mongodb.scala.Completed]>`
347415
can insert *multiple* :ref:`documents <bson-document-format>` into a
348416
collection.
349-
417+
350418
The following example inserts three new documents into the
351419
``inventory`` collection. If the documents do not specify an
352420
``_id`` field, the Scala driver adds the ``_id`` field with
353421
an ObjectId value to each document. See :ref:`write-op-insert-behavior`.
354422

355423
- id: csharp
356424
content: |
425+
.. versionadded:: 3.2
426+
357427
:csharp-api:`IMongoCollection.InsertMany()<M_MongoDB_Driver_IMongoCollection_1_InsertMany>`
358428
can insert *multiple* :ref:`documents <bson-document-format>`
359429
into a collection. Pass an enumerable collection of documents
@@ -375,31 +445,46 @@ Insert Multiple Documents
375445
the newly inserted documents ``_id`` field values. See the
376446
:ref:`reference <insertMany-examples>` for an example.
377447

448+
To retrieve the inserted documents, :ref:`query the collection
449+
<read-operations-query-document>`:
450+
378451
- id: python
379452
content: |
380453
:py:meth:`~pymongo.collection.Collection.insert_many` returns
381454
an instance of :py:class:`pymongo.results.InsertManyResult`
382455
whose ``inserted_ids`` field is a list containing the ``_id``
383456
of each newly inserted document.
384457

458+
To retrieve the inserted documents, :ref:`query the collection
459+
<read-operations-query-document>`:
460+
385461
- id: java-sync
386462
content: |
387463

464+
To retrieve the inserted documents, :ref:`query the collection
465+
<read-operations-query-document>`:
466+
388467
- id: java-async
389468
content: |
390469
`com.mongodb.reactivestreams.client.MongoCollection.html.insertMany
391470
<http://mongodb.github.io/mongo-java-driver-reactivestreams/1.6/javadoc/com/mongodb/reactivestreams/client/MongoCollection.html#insertMany(java.util.List)>`_
392471
returns a `Publisher <http://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/org/reactivestreams/Publisher.html>`_
393-
object. The ``Publisher`` inserts the document into a collection
472+
object. The ``Publisher`` inserts the document into a collection
394473
when subscribers request data.
395474

475+
To retrieve the inserted documents, :ref:`query the collection
476+
<read-operations-query-document>`:
477+
396478
- id: nodejs
397479
content: |
398480
:node-api:`insertMany() <Collection.html#insertMany>` returns a
399481
promise that provides a ``result``. The ``result.insertedIds``
400482
field contains an array with the ``_id`` of each newly inserted
401483
document.
402484

485+
To retrieve the inserted documents, :ref:`query the collection
486+
<read-operations-query-document>`:
487+
403488
- id: php
404489
content: |
405490
Upon successful insert, the
@@ -411,6 +496,9 @@ Insert Multiple Documents
411496
:phpmethod:`getInsertedIds() <phpmethod.MongoDB\\InsertManyResult::getInsertedIds>`
412497
method returns the ``_id`` of each newly inserted document.
413498

499+
To retrieve the inserted documents, :ref:`query the collection
500+
<read-operations-query-document>`:
501+
414502
- id: perl
415503
content: |
416504
Upon successful insert, the
@@ -420,6 +508,9 @@ Insert Multiple Documents
420508
whose ``inserted_ids`` attribute is a list containing the
421509
``_id`` of each newly inserted document.
422510

511+
To retrieve the inserted documents, :ref:`query the collection
512+
<read-operations-query-document>`:
513+
423514
- id: ruby
424515
content: |
425516
Upon successful insert, the
@@ -429,20 +520,26 @@ Insert Multiple Documents
429520
whose ``inserted_ids`` attribute is a list containing the
430521
``_id`` of each newly inserted document.
431522

523+
To retrieve the inserted documents, :ref:`query the collection
524+
<read-operations-query-document>`:
525+
432526
- id: scala
433527
content: |
434528
Upon successful insert, the
435-
:scala-api:`insertMany()<insertMany(documents:Seq[_<:TResult],options:org.mongodb.scala.model.InsertManyOptions):org.mongodb.scala.SingleObservable[org.mongodb.scala.Completed]>`
529+
:scala-api:`insertMany()<insertMany(documents:Seq[_<:TResult],options:org.mongodb.scala.model.InsertManyOptions):org.mongodb.scala.SingleObservable[org.mongodb.scala.Completed]>`
436530
method returns an `Observable <http://mongodb.github.io/mongo-scala-driver/2.1/reference/observables/>`_ with a type parameter indicating when
437531
the operation has completed or with either a
438-
``com.mongodb.DuplicateKeyException`` or
532+
``com.mongodb.DuplicateKeyException`` or
439533
``com.mongodb.MongoException``.
440534

535+
To retrieve the inserted documents, :ref:`query the collection
536+
<read-operations-query-document>`:
537+
441538
- id: csharp
442539
content: |
443540

444-
To retrieve the inserted documents, :ref:`query the collection
445-
<read-operations-query-document>`:
541+
To retrieve the inserted documents, :ref:`query the collection
542+
<read-operations-query-document>`:
446543

447544
.. include:: /includes/driver-example-query-7.rst
448545

@@ -457,6 +554,8 @@ Collection Creation
457554
If the collection does not currently exist, insert operations will
458555
create the collection.
459556

557+
.. _insert-id-field:
558+
460559
``_id`` Field
461560
~~~~~~~~~~~~~
462561

0 commit comments

Comments
 (0)