documentation_examples

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

Go Driver Documentation Examples
================================

examples.go contains numerous documentation examples that are rendered in various locations on www.mongodb.com/docs.
Each example is delineated with starting and ending comments (// Start/End Example #). All examples in examples.go
are valid Go driver code. Each example is run as part of our CI with examples_test.go, so all code is up-to-date and
accurate. We recommend using www.mongodb.com/docs to interact with these examples rather than viewing these files
directly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregationExamples

func AggregationExamples(t *testing.T, db *mongo.Database)

AggregationExamples contains examples of aggregation operations. Appears at https://www.mongodb.com/docs/manual/aggregation/.

func CausalConsistencyExamples

func CausalConsistencyExamples(client *mongo.Client) error

CausalConsistencyExamples contains examples of causal consistency usage. Appears at https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency/.

func ChangeStreamExamples

func ChangeStreamExamples(t *testing.T, db *mongo.Database)

ChangeStreamExamples contains examples of changestream operations. Appears at https://www.mongodb.com/docs/manual/changeStreams/.

func CommitWithRetry

func CommitWithRetry(sctx mongo.SessionContext) error

CommitWithRetry is an example function demonstrating transaction commit with retry logic.

func DeleteExamples

func DeleteExamples(t *testing.T, db *mongo.Database)

DeleteExamples contains examples of delete operations. Appears at https://www.mongodb.com/docs/manual/tutorial/remove-documents/.

func IndexExamples

func IndexExamples(t *testing.T, db *mongo.Database)

IndexExamples contains examples of Index operations. Appears at https://www.mongodb.com/docs/manual/indexes/.

func InsertExamples

func InsertExamples(t *testing.T, db *mongo.Database)

InsertExamples contains examples for insert operations. Appears at https://www.mongodb.com/docs/manual/tutorial/insert-documents/.

func ProjectionExamples

func ProjectionExamples(t *testing.T, db *mongo.Database)

ProjectionExamples contains examples for specifying projections in find operations. Appears at https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results/.

func QueryArrayEmbeddedDocumentsExamples

func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database)

QueryArrayEmbeddedDocumentsExamples contains examples for querying fields with arrays and embedded documents. Appears at https://www.mongodb.com/docs/manual/tutorial/query-array-of-documents/.

func QueryArraysExamples

func QueryArraysExamples(t *testing.T, db *mongo.Database)

QueryArraysExamples contains examples for querying array fields. Appears at https://www.mongodb.com/docs/manual/tutorial/query-arrays/.

func QueryEmbeddedDocumentsExamples

func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database)

QueryEmbeddedDocumentsExamples contains examples for querying embedded document fields. Appears at https://www.mongodb.com/docs/manual/tutorial/query-embedded-documents/.

func QueryNullMissingFieldsExamples

func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database)

QueryNullMissingFieldsExamples contains examples for querying fields that are null or missing. Appears at https://www.mongodb.com/docs/manual/tutorial/query-for-null-fields/.

func QueryToplevelFieldsExamples

func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database)

QueryToplevelFieldsExamples contains examples for querying top-level fields. Appears at https://www.mongodb.com/docs/manual/tutorial/query-documents/.

func RunCommandExamples

func RunCommandExamples(t *testing.T, db *mongo.Database)

RunCommandExamples contains examples of RunCommand operations. Appears at https://www.mongodb.com/docs/manual/reference/command/collStats/.

func RunTransactionWithRetry

func RunTransactionWithRetry(sctx mongo.SessionContext, txnFn func(mongo.SessionContext) error) error

RunTransactionWithRetry is an example function demonstrating transaction retry logic.

func SnapshotQueryExamples

func SnapshotQueryExamples(mt *mtest.T)

SnapshotQuery examples runs examples of using sessions with Snapshot enabled. These appear at https://www.mongodb.com/docs/manual/tutorial/long-running-queries/.

func StableAPIDeprecationErrorsExample

func StableAPIDeprecationErrorsExample()

StableAPIDeprecationErrorsExample is an example of creating a client with stable API with deprecation errors.

func StableAPIExample

func StableAPIExample()

StableAPIExample is an example of creating a client with stable API.

func StableAPIExamples

func StableAPIExamples()

StableAPIExamples runs all stable API examples. These appear at https://www.mongodb.com/docs/manual/reference/stable-api/.

func StableAPINonStrictExample

func StableAPINonStrictExample()

StableAPINonStrictExample is an example of creating a client with non-strict stable API.

func StableAPIStrictCountExample

func StableAPIStrictCountExample(t *testing.T)

StableAPIStrictCountExample is an example of using CountDocuments instead of a traditional count with a strict stable API since the count command does not belong to API version 1.

func StableAPIStrictExample

func StableAPIStrictExample()

StableAPIStrictExample is an example of creating a client with strict stable API.

func TransactionsExamples

func TransactionsExamples(ctx context.Context, client *mongo.Client) error

TransactionsExamples contains examples for transaction operations.

func UpdateEmployeeInfo

func UpdateEmployeeInfo(ctx context.Context, client *mongo.Client) error

UpdateEmployeeInfo is an example function demonstrating transactions.

func UpdateExamples

func UpdateExamples(t *testing.T, db *mongo.Database)

UpdateExamples contains examples of update operations. Appears at https://www.mongodb.com/docs/manual/tutorial/update-documents/.

func WithTransactionExample

func WithTransactionExample(ctx context.Context) error

WithTransactionExample is an example of using the Session.WithTransaction function.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL