-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fleshed out code examples and ref as includes
- Loading branch information
1 parent
e9a9862
commit a64eac7
Showing
4 changed files
with
66 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
#include <mongoc/mongoc.h> | ||
#include <bson/bson.h> | ||
|
||
int main (void) { | ||
|
||
// start-connect-to-atlas | ||
// Initialize the C Driver | ||
mongoc_init (); | ||
|
||
// Create a new client and set tls option to true | ||
mongoc_client_t *client = mongoc_client_new ("mongodb+srv://<db_username>:<db_password>@<hostname/port>/?replicaSet=myRepl&tls=true"); | ||
|
||
// { Do database work here } | ||
|
||
// Cleanup | ||
mongoc_client_destroy (client); | ||
mongoc_cleanup (); | ||
// end-connect-to-atlas | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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,28 @@ | ||
#include <mongoc/mongoc.h> | ||
#include <bson/bson.h> | ||
|
||
int main(void) { | ||
|
||
// start-connect | ||
// Intialize the MongoDB C Driver | ||
mongoc_init (); | ||
|
||
bson_error_t error; | ||
|
||
// Create a new client and set TLS option to true | ||
mongoc_uri_t *uri = mongoc_uri_new_with_error ("mongodb://localhost:27017", &error); | ||
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_TLS, true); | ||
if (!uri) { | ||
fprintf (stderr, "failed to parse URI, error: %s\n", error.message); | ||
goto cleanup; | ||
} | ||
|
||
mongoc_client_t *client = mongoc_client_new_from_uri (uri); | ||
|
||
// { Do database work here } | ||
|
||
cleanup: | ||
mongoc_client_destroy (client); | ||
mongoc_cleanup (); | ||
// end-connect | ||
} |