Skip to content

Conversation

@egiurleo
Copy link
Contributor

@egiurleo egiurleo commented Jun 8, 2020

No description provided.

@egiurleo egiurleo requested a review from p-mongo June 8, 2020 16:36
Update Options
~~~~~~~~~~~~~~

To add options to an update command, specify them as key value pairs in the options
Copy link
Contributor

Choose a reason for hiding this comment

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

"key-value" pairs?

result = artists.update_one(
{ :name => 'Goldie' },
{ "$inc" => { :plays => 1 } },
{ hint: { _id: 1 } }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is _id index used for the update rather than the find, i.e. this call searches for the document twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This call doesn't search for documents twice! My understanding is that find just creates a View on the collection, and then the update command performs the search (with the specified index) and the update.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case I am confused: how would the _id index be used with a query on name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll think of a clearer example.

- The session to use for this operation.
* - ``upsert``
- Whether to upsert if the document doesn't exist. Cannot be used on
``find_one_and_delete`` operation.
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the :return_document that was in the example previously, does it still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup! Thanks for pointing that out.

@egiurleo egiurleo requested a review from p-mongo June 8, 2020 20:49
@egiurleo egiurleo merged commit 93e772d into mongodb:master Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants