Skip to content

DOCS-5167: Move 3.0 dot notation change example out of API reference #2274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ description: |

.. include:: /includes/fact-mongodb30-upsert-id.rst

For an example, see :ref:`mongodb30-upsert-id`.

interface: method
name: query
operation: db.collection.update
Expand Down
7 changes: 7 additions & 0 deletions source/includes/fact-mongodb30-upsert-id-example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
For example, the following will raise an error:

.. code-block:: javascript

db.collection.update( { "_id.authorID": 1 },
{ "name": "Robert Frost" },
{ upsert: true } )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imprecise. Exactly why would the example shown raise an error?

db.foo.update( { "_id.authorID": 2 }, { "name": "Robert Frost" }, { upsert: true } )
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 111,
"errmsg" : "field at '_id' must be exactly specified, field at sub-path '_id.authorID'found"
}
})
db.foo.update( { "_id.authorID": 1 }, { "name": "2Robert Frost" }, { upsert: true } )
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

10 changes: 2 additions & 8 deletions source/includes/fact-mongodb30-upsert-id.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
When you execute an :method:`~db.collection.update()` with the ``upsert``
option, you can no longer use :ref:`document-dot-notation` to select only on
part of the ``_id`` field. For example, the following will raise an error:

.. code-block:: javascript

db.collection.update( { "_id.authorID": 1 },
{ "name": "Robert Frost" },
{ upsert: true } )
option, you can not use :ref:`dot notation <document-dot-notation>` to select only
part of the ``_id`` field.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Given my test examples, the sentence needs to be more precise. Afterwards, could you have scott code review?

db.foo.update( { "_id.authorID": 2 }, { "name": "Robert Frost" }, { upsert: true } )
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 111,
"errmsg" : "field at '_id' must be exactly specified, field at sub-path '_id.authorID'found"
}
})
db.foo.update( { "_id.authorID": 1 }, { "name": "2Robert Frost" }, { upsert: true } )
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

9 changes: 9 additions & 0 deletions source/reference/method/db.collection.update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ Sharded Collections

.. _update-method-examples:

.. _mongodb30-upsert-id:

Upsert with Query on ``_id``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/fact-mongodb30-upsert-id.rst

.. include:: /includes/fact-mongodb30-upsert-id-example.rst

Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions source/release-notes/3.0-compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ General Compatibility Changes

.. include:: /includes/fact-mongodb30-upsert-id.rst

.. include:: /includes/fact-mongodb30-upsert-id-example.rst

Deprecate Access to ``system.indexes`` and ``system.namespaces``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down