-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-13862 delete one usage example #6
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
Merged
kyuan-mongodb
merged 11 commits into
mongodb:master
from
kyuan-mongodb:DOCSP-13862-UsageExampleDeleteOne
Jul 29, 2021
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ecceaf7
added usage example deleteOne page
kyuan-mongodb 2fed0bb
updated connection uri
kyuan-mongodb ed28820
implemented PR feedback
kyuan-mongodb 8327c4a
implemented PR feedback
kyuan-mongodb a46f60e
added in findOne link
kyuan-mongodb d692984
removed duplicate wording
kyuan-mongodb f951e74
reworded results section
kyuan-mongodb 63a705e
updated file structure and content based on other PRs
kyuan-mongodb 64ee139
implemented PR feedback
kyuan-mongodb c56dcc2
Merge remote-tracking branch 'origin' into DOCSP-13862-UsageExampleDe…
kyuan-mongodb f240370
merged with master
kyuan-mongodb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
// Replace the uri string with your MongoDB deployment's connection string. | ||
const uri = "mongodb+srv://<username>:<password>@<cluster-address>/test?w=majority" | ||
|
||
func main() { | ||
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
defer func() { | ||
if err = client.Disconnect(context.TODO()); err != nil { | ||
panic(err) | ||
} | ||
}() | ||
|
||
// begin deleteOne | ||
coll := client.Database("sample_mflix").Collection("movies") | ||
result, err := coll.DeleteOne(context.TODO(), bson.D{{"title", "Twilight"}}) | ||
// end deleteOne | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// When you run this file for the first time, it should print "Documents deleted: 1" | ||
fmt.Printf("Documents deleted: %d\n", result.DeletedCount) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,50 @@ Delete a Document | |
================= | ||
|
||
.. default-domain:: mongodb | ||
|
||
You can delete a document in a collection using the ``DeleteOne()`` | ||
method. | ||
|
||
The following example specifies a query filter that matches documents in | ||
the ``movies`` collection with the value "Twilight" in the ``title`` field, and | ||
deletes the first document that matches. | ||
|
||
.. include:: /includes/usage-examples/run-example-tip.rst | ||
|
||
.. literalinclude:: /includes/usage-examples/code-snippets/deleteOne.go | ||
:start-after: begin deleteOne | ||
:end-before: end deleteOne | ||
:emphasize-lines: 2 | ||
:language: go | ||
:dedent: | ||
|
||
Click here <TODO> to see a fully runnable example. | ||
biniona-mongodb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Expected Result | ||
--------------- | ||
|
||
After running the preceding code snippet, you should not be able to find | ||
the following document in the ``movies`` collection: | ||
|
||
.. code-block:: json | ||
|
||
{ "_id": { "$oid": "573a13bff29313caabd5e06b" }, | ||
... | ||
"title": "Twilight", | ||
... | ||
} | ||
|
||
For an example on how to find a document, see our :doc:`Find | ||
One Usage Example </usage-examples/findOne>`. | ||
|
||
Additional Information | ||
---------------------- | ||
|
||
For more information on deleting documents, specifying query filters, | ||
and handling potential errors, see our guide on <TODO: | ||
Deleting a Document>. | ||
|
||
API Documentation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
`DeleteOne() <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#Collection.DeleteOne>`__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ The following example passes a query filter and an update parameter to the | |
field is "Sydney" and multiplies the ``price`` field in the matching | ||
documents by a factor of *1.15*: | ||
|
||
.. include:: /includes/run-example-tip.rst | ||
.. include:: /includes/usage-examples/run-example-tip.rst | ||
|
||
.. literalinclude:: /code-snippets/updateMany.go | ||
.. literalinclude:: /includes/usage-examples/code-snippets/updateMany.go | ||
:start-after: begin updatemany | ||
:end-before: end updatemany | ||
:emphasize-lines: 5 | ||
|
@@ -55,4 +55,4 @@ see the :manual:`MongoDB update operator reference documentation | |
API Documentation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
`UpdateMany() <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#Collection.UpdateMany>`_ | ||
`UpdateMany() <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#Collection.UpdateMany>`__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,9 @@ The following example passes a query filter and an update parameter to the | |
by the value of its ``_id`` field and creates a new field in that document called | ||
``avg_rating`` with a value of *4.4*: | ||
|
||
.. include:: /includes/run-example-tip.rst | ||
.. include:: /includes/usage-examples/run-example-tip.rst | ||
|
||
.. literalinclude:: /code-snippets/updateOne.go | ||
.. literalinclude:: /includes/usage-examples/code-snippets/updateOne.go | ||
:start-after: begin updateone | ||
:end-before: end updateone | ||
:emphasize-lines: 6 | ||
|
@@ -55,4 +55,4 @@ see the :manual:`MongoDB update operator reference documentation | |
API Documentation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
`UpdateOne() <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#Collection.UpdateOne>`_ | ||
`UpdateOne() <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#Collection.UpdateOne>`__ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.