Skip to content

CXX-3082 Add Comprehensive Examples (bsoncxx) #1208

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
merged 31 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
43894dc
Silence common warnings in API examples
eramongodb Sep 13, 2024
0b7f138
Add bsoncxx and mongocxx topic pages for guides and explanations
eramongodb Sep 13, 2024
d55c71f
Add bsoncxx topic page for using BSON documents
eramongodb Sep 13, 2024
96d6e50
Add BSON document usage examples
eramongodb Sep 13, 2024
6b2c4f5
Add bsoncxx error handling examples
eramongodb Sep 13, 2024
45eb641
Add decimal128 examples
eramongodb Sep 13, 2024
dccdfec
Add oid examples
eramongodb Sep 13, 2024
675dcd8
Add validation examples
eramongodb Sep 13, 2024
5417451
CXX-3101 Workaround missing features of mnmlstc/core polyfills
eramongodb Sep 13, 2024
6edb286
Refactor API examples to use component registration pattern
eramongodb Sep 13, 2024
685506d
Ensure assertions in examples are always evaluated
eramongodb Sep 13, 2024
a99e9e6
Fix section heading levels
eramongodb Sep 16, 2024
aa26db1
Simplify runner registration
eramongodb Sep 16, 2024
e4ecf4a
Note where EXAMPLES_COMPONENT_NAME is defined
eramongodb Sep 16, 2024
724d7f6
Fix comment documenting argv[2]
eramongodb Sep 16, 2024
9e34625
Merge remote-tracking branch 'upstream/master' into cxx-3082
eramongodb Sep 16, 2024
2e70e4e
Group topic pages by library + reword titles
eramongodb Sep 16, 2024
3c17f5a
Remove redundant call to add_dependencies
eramongodb Sep 16, 2024
dbe38bd
Move references to external resources into page description
eramongodb Sep 18, 2024
d6bc01a
Formatting
eramongodb Sep 18, 2024
64dc314
Merge remote-tracking branch 'upstream/master' into cxx-3082
eramongodb Sep 18, 2024
abafa8b
Merge remote-tracking branch 'upstream/master' into cxx-3082
eramongodb Sep 19, 2024
5aabcf1
Merge remote-tracking branch 'upstream/master' into cxx-3082
eramongodb Sep 19, 2024
b9ab81c
Fix reference to element in validator example
eramongodb Sep 24, 2024
5a9b6dc
Fix sign bit in decimal128/from_bytes.cpp description
eramongodb Sep 24, 2024
c1fd75e
Merge remote-tracking branch 'upstream/master' into cxx-3082
eramongodb Sep 24, 2024
68346a1
Use `--flag arg` syntax for CLI arguments
eramongodb Sep 25, 2024
33f23ad
Better integer type consistency for jobs value
eramongodb Sep 25, 2024
1742faa
Print invalid argument on error
eramongodb Sep 25, 2024
01661e3
Avoid implying equal OID counter value results
eramongodb Sep 25, 2024
64fee4a
Split sub-doc and sub-arr examples into make_* and sub_*
eramongodb Sep 25, 2024
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
25 changes: 25 additions & 0 deletions docs/api/bsoncxx/examples/bson_documents/access_array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Access an Array Element

## By Iteration

### Basic Example

@snippet api/bsoncxx/examples/bson_documents/access_array/basic.cpp Example

### Using Iterators

@snippet api/bsoncxx/examples/bson_documents/access_array/iterators.cpp Example

### Using Algorithms

@snippet api/bsoncxx/examples/bson_documents/access_array/algorithms.cpp Example

## By Key

### Using find()

@snippet api/bsoncxx/examples/bson_documents/access_array/find.cpp Example

### Using the Subscript Operator

@snippet api/bsoncxx/examples/bson_documents/access_array/subscript.cpp Example
25 changes: 25 additions & 0 deletions docs/api/bsoncxx/examples/bson_documents/access_doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Access a Document Element

## By Iteration

### Basic Example

@snippet api/bsoncxx/examples/bson_documents/access_doc/basic.cpp Example

### Using Iterators

@snippet api/bsoncxx/examples/bson_documents/access_doc/iterators.cpp Example

### Using Algorithms

@snippet api/bsoncxx/examples/bson_documents/access_doc/algorithms.cpp Example

## By Key

### Using find()

@snippet api/bsoncxx/examples/bson_documents/access_doc/find.cpp Example

### Using the Subscript Operator

@snippet api/bsoncxx/examples/bson_documents/access_doc/subscript.cpp Example
71 changes: 71 additions & 0 deletions docs/api/bsoncxx/examples/bson_documents/create_array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Create an Array

## From a JSON String

### Basic Example

@snippet api/bsoncxx/examples/bson_documents/create_array/json_basic.cpp Example

### With Extended JSON

@snippet api/bsoncxx/examples/bson_documents/create_array/json_extended.cpp Example

### With a Sub-Document

@snippet api/bsoncxx/examples/bson_documents/create_array/json_sub_document.cpp Example

### With a Sub-Array

@snippet api/bsoncxx/examples/bson_documents/create_array/json_sub_array.cpp Example

### With a User-Defined Literal

@snippet api/bsoncxx/examples/bson_documents/create_array/json_udl.cpp Example

## Using the Basic Builder

### Basic Example

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_basic.cpp Example

### With make_document

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_make_document.cpp Example

### With Multiple Appends

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_append.cpp Example

### To Create Multiple Documents

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_reset.cpp Example

### With a Value Type

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_value_type.cpp Example

### With a BSON Type

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_bson_type.cpp Example

### With a BSON Value

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_bson_value.cpp Example

### With a Sub-Document

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_sub_document.cpp Example

### With a Sub-Array

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_sub_array.cpp Example

## From Raw Bytes

### As a View

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_raw_view.cpp Example

### As a Value

@snippet api/bsoncxx/examples/bson_documents/create_array/builder_raw_value.cpp Example
71 changes: 71 additions & 0 deletions docs/api/bsoncxx/examples/bson_documents/create_doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Create a Document

## From a JSON String

### Basic Example

@snippet api/bsoncxx/examples/bson_documents/create_doc/json_basic.cpp Example

### With Extended JSON

@snippet api/bsoncxx/examples/bson_documents/create_doc/json_extended.cpp Example

### With a Sub-Document

@snippet api/bsoncxx/examples/bson_documents/create_doc/json_sub_document.cpp Example

### With a Sub-Array

@snippet api/bsoncxx/examples/bson_documents/create_doc/json_sub_array.cpp Example

### With a User-Defined Literal

@snippet api/bsoncxx/examples/bson_documents/create_doc/json_udl.cpp Example

## Using the Basic Builder

### Basic Example

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_basic.cpp Example

### With make_document

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_make_document.cpp Example

### With Multiple Appends

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_append.cpp Example

### To Create Multiple Documents

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_reset.cpp Example

### With a Value Type

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_value_type.cpp Example

### With a BSON Type

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_bson_type.cpp Example

### With a BSON Value

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_bson_value.cpp Example

### With a Sub-Document

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_sub_document.cpp Example

### With a Sub-Array

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_sub_array.cpp Example

## From Raw Bytes

### As a View

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_raw_view.cpp Example

### As a Value

@snippet api/bsoncxx/examples/bson_documents/create_doc/builder_raw_value.cpp Example
31 changes: 31 additions & 0 deletions docs/api/bsoncxx/examples/bson_documents/elements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Query an Element

## In a Document

### For a Single Type

@snippet api/bsoncxx/examples/bson_documents/elements/doc_single.cpp Example

### For Multiple Types

@snippet api/bsoncxx/examples/bson_documents/elements/doc_multi.cpp Example

## In an Array

### For Single Type

@snippet api/bsoncxx/examples/bson_documents/elements/arr_single.cpp Example

### For Multiple Types

@snippet api/bsoncxx/examples/bson_documents/elements/arr_multi.cpp Example

## Comparison

### By Type

@snippet api/bsoncxx/examples/bson_documents/elements/cmp_type.cpp Example

### By BSON Value

@snippet api/bsoncxx/examples/bson_documents/elements/cmp_bson_value.cpp Example
9 changes: 9 additions & 0 deletions docs/api/bsoncxx/examples/bson_documents/json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Convert to a JSON String

## From a Document

@snippet api/bsoncxx/examples/bson_documents/json/document.cpp Example

## From an Array

@snippet api/bsoncxx/examples/bson_documents/json/array.cpp Example
39 changes: 39 additions & 0 deletions docs/api/bsoncxx/examples/bson_documents/values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Obtain a BSON Value

## From a BSON Type

### As a View

@snippet api/bsoncxx/examples/bson_documents/values/bson_type_view.cpp Example

### As a Value

@snippet api/bsoncxx/examples/bson_documents/values/bson_type_value.cpp Example

## From a Document Element

### As a View

@snippet api/bsoncxx/examples/bson_documents/values/doc_view.cpp Example

### As a Value

@snippet api/bsoncxx/examples/bson_documents/values/doc_value.cpp Example

## From an Array Element

### As a View

@snippet api/bsoncxx/examples/bson_documents/values/arr_view.cpp Example

### As a Value

@snippet api/bsoncxx/examples/bson_documents/values/arr_value.cpp Example

## From a Value Type

@snippet api/bsoncxx/examples/bson_documents/values/value_type.cpp Example

## With make_value

@snippet api/bsoncxx/examples/bson_documents/values/make_value.cpp Example
115 changes: 115 additions & 0 deletions docs/api/bsoncxx/examples/bson_errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Create a BSON Document

## From an Invalid JSON String

@snippet api/bsoncxx/examples/bson_errors/create_json.cpp Example

## Using the Basic Document Builder

### Basic Append Failure

@snippet api/bsoncxx/examples/bson_errors/create_doc_append.cpp Example

### Sub-Document Append Failure

@snippet api/bsoncxx/examples/bson_errors/create_doc_append_sub_document.cpp Example

### Sub-Array Append Failure

@snippet api/bsoncxx/examples/bson_errors/create_doc_append_sub_array.cpp Example

## Using the Basic Array Builder

### Basic Append Failure

@snippet api/bsoncxx/examples/bson_errors/create_arr_append.cpp Example

### Sub-Document Append Failure

@snippet api/bsoncxx/examples/bson_errors/create_arr_append_sub_document.cpp Example

### Sub-Array Append Failure

@snippet api/bsoncxx/examples/bson_errors/create_arr_append_sub_array.cpp Example

# Access a Document Element

## By Iteration

### End Iterators

@snippet api/bsoncxx/examples/bson_errors/access_doc_iter_end.cpp Example

### Invalid BSON Documents

@snippet api/bsoncxx/examples/bson_errors/access_doc_iter_invalid.cpp Example

## By Key

### Missing Element

@snippet api/bsoncxx/examples/bson_errors/access_doc_key_missing.cpp Example

# Access an Array Element

## By Iteration

### End Iterators

@snippet api/bsoncxx/examples/bson_errors/access_arr_iter_end.cpp Example

### Invalid BSON Arrays

@snippet api/bsoncxx/examples/bson_errors/access_arr_iter_invalid.cpp Example

## By Key

### Missing Element

@snippet api/bsoncxx/examples/bson_errors/access_arr_key_missing.cpp Example

# Query an Element

## In a Document

### Invalid Element

@snippet api/bsoncxx/examples/bson_errors/query_element_doc_invalid.cpp Example

### Invalid Type

@snippet api/bsoncxx/examples/bson_errors/query_element_doc_invalid_type.cpp Example

## In an Array

### Invalid Element

@snippet api/bsoncxx/examples/bson_errors/query_element_arr_invalid.cpp Example

### Invalid Type

@snippet api/bsoncxx/examples/bson_errors/query_element_arr_invalid_type.cpp Example

# Use a BSON Value

## Query an Invalid Type

@snippet api/bsoncxx/examples/bson_errors/query_bson_value_invalid_type.cpp Example

## Create an Invalid Value

@snippet api/bsoncxx/examples/bson_errors/create_bson_value_invalid_type.cpp Example

## From an Invalid Element

@snippet api/bsoncxx/examples/bson_errors/create_bson_value_invalid_element.cpp Example

# Convert to a JSON String

## From an Invalid BSON Document

@snippet api/bsoncxx/examples/bson_errors/to_json_invalid_doc.cpp Example

## From an Invalid BSON Array

@snippet api/bsoncxx/examples/bson_errors/to_json_invalid_arr.cpp Example
Loading