-
Notifications
You must be signed in to change notification settings - Fork 13
(DOCSP-43745) Connect to MongoDB #61
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
amalhotra-mdb
merged 16 commits into
mongodb:standardization
from
amalhotra-mdb:DOCSP-43745
Oct 2, 2024
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
862c2c9
Fill out root page for Connect to MongoDB
amalhotra-mdb e43f737
sample app code changes
amalhotra-mdb 57a6758
code fixes
amalhotra-mdb 2b403ee
define client in stable api code
amalhotra-mdb ce96476
review changes
amalhotra-mdb 35a21cc
remove port from connection str
amalhotra-mdb 791ce3b
.
amalhotra-mdb f20cb28
fix comments & toc tree
amalhotra-mdb 1d12e6c
fix TODO comments and TOC tree
amalhotra-mdb 04f50c6
review changes
amalhotra-mdb 4fbd2ee
Merge branch 'standardization' into DOCSP-43745
amalhotra-mdb d31e058
connection string fix
amalhotra-mdb 58de8d7
code highlight fix
amalhotra-mdb a6db35d
reveal tls in toc
amalhotra-mdb 080cbbe
review code fixes
amalhotra-mdb 1b4867c
review changes
amalhotra-mdb 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
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,18 @@ | ||
.. tabs:: | ||
|
||
.. tab:: Connection String | ||
:tabid: connectionstring | ||
|
||
.. code-block:: c | ||
|
||
client = mongoc_client_new("mongodb://<db_username>:<db_password>@<hostname>/?compressors=snappy,zlib,zstd"); | ||
|
||
.. tab:: MongoC URI Options | ||
:tabid: mongocurioptions | ||
|
||
.. code-block:: c | ||
|
||
uri = mongoc_uri_new ("mongodb://localhost:27017"); | ||
mongoc_uri_set_compressors (uri, "snappy,zlib,zstd"); | ||
|
||
client = mongoc_client_new_from_uri (uri); |
19 changes: 19 additions & 0 deletions
19
source/includes/connect/disable-host-verification-tabs.rst
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,19 @@ | ||
.. tabs:: | ||
|
||
.. tab:: Connection String | ||
:tabid: connectionstring | ||
|
||
.. code-block:: c | ||
|
||
client = mongoc_client_new("mongodb://<db_username>:<db_password>@<hostname>/?tls=true&tlsAllowInvalidHostnames=true"); | ||
|
||
.. tab:: MongoC URI Options | ||
:tabid: mongocurioptions | ||
|
||
.. code-block:: c | ||
|
||
uri = mongoc_uri_new ("mongodb://localhost:27017"); | ||
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_TLS, true); | ||
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_TLSALLOWINVALIDHOSTNAMES, true); | ||
|
||
client = mongoc_client_new_from_uri (uri); |
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,18 @@ | ||
.. tabs:: | ||
|
||
.. tab:: Connection String | ||
:tabid: connectionstring | ||
|
||
.. code-block:: c | ||
|
||
client = mongoc_client_new("mongodb://<db_username>:<db_password>@<hostname>/?tls=true"); | ||
|
||
.. tab:: MongoC URI Options | ||
:tabid: mongocurioptions | ||
|
||
.. code-block:: c | ||
|
||
uri = mongoc_uri_new ("mongodb://localhost:27017"); | ||
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_TLS, true); | ||
|
||
client = mongoc_client_new_from_uri (uri); |
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,18 @@ | ||
.. tabs:: | ||
|
||
.. tab:: Connection String | ||
:tabid: connectionstring | ||
|
||
.. code-block:: c | ||
|
||
client = mongoc_client_new("mongodb://<db_username>:<db_password>@<hostname>/?compressors=zlib&zlibCompressionLevel=<zlib_compression_level"); | ||
|
||
.. tab:: MongoC URI Options | ||
:tabid: mongocurioptions | ||
|
||
.. code-block:: c | ||
|
||
uri = mongoc_uri_new ("mongodb://localhost:27017"); | ||
mongoc_uri_set_option_as_int32 (uri, MONGOC_URI_ZLIBCOMPRESSIONLEVEL, <zlib-compression-level>); | ||
|
||
client = mongoc_client_new_from_uri (uri); |
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,35 @@ | ||
#include <mongoc/mongoc.h> | ||
#include <bson/bson.h> | ||
|
||
int main(void) { | ||
|
||
mongoc_uri_t* uri = NULL; | ||
mongoc_client_t *client = NULL; | ||
mongoc_database_t *database = NULL; | ||
bson_t *ping = NULL, reply = BSON_INITIALIZER; | ||
bson_error_t error; | ||
|
||
mongoc_init(); | ||
|
||
// Start example code here | ||
|
||
// End example code here | ||
kevinAlbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
database = mongoc_client_get_database (client, "admin"); | ||
|
||
ping = BCON_NEW ("ping", BCON_INT32 (1)); | ||
|
||
if (!mongoc_client_command_simple (client, "admin", ping, NULL, &reply, &error)) { | ||
fprintf (stderr, "%s\n", error.message); | ||
goto cleanup; | ||
} | ||
printf ("Pinged your deployment. You successfully connected to MongoDB!\n"); | ||
|
||
cleanup: | ||
bson_destroy (&reply); | ||
bson_destroy (ping); | ||
mongoc_database_destroy (database); | ||
mongoc_client_destroy (client); | ||
mongoc_uri_destroy (uri); | ||
mongoc_cleanup (); | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest not using
uri
for consistency with tabbed examples.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet addressed.