Skip to content

Commit 2f0b9da

Browse files
authored
DOCSP-17096: versioned api ex (#745)
* DOCSP-17096: versioned api connection instructions * DOCSP-17096: versioned api connection instructions * DOCSP-17096: versioned api connection instructions * DOCSP-17096: versioned api connection instructions * DOCSP-17096: versioned api connection instructions * DOCSP-17096: versioned api connection instructions * DOCSP-17096: versioned api connection instructions * DOCSP-17096: versioned api connection instructions * DOCSP-17096: versioned api connection instructions
1 parent 894b059 commit 2f0b9da

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

source/c.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Connect to MongoDB Atlas
5959

6060
mongoc_init ();
6161

62+
// Replace the uri string with your MongoDB deployment's connection string.
6263
client = mongoc_client_new(
6364
"mongodb+srv://<username>:<password>@<cluster-url>/test?retryWrites=true&w=majority"
6465
);
@@ -77,6 +78,35 @@ Connect to MongoDB Atlas
7778
See `Advanced Connections <http://mongoc.org/libmongoc/current/advanced-connections.html>`__
7879
for more ways to connect.
7980

81+
Versioned API
82+
-------------
83+
84+
You can use the `Versioned API
85+
<https://docs.mongodb.com/v5.0/reference/versioned-api/>`__ feature
86+
starting with MongoDB Server version 5.0 and C Driver version 1.18. When
87+
you use the Versioned API feature, you can update your driver or server
88+
without worrying about backward compatibility issues with any commands
89+
covered by the Versioned API. To use this feature, construct a MongoDB
90+
client instance, specifying a version of the Versioned API:
91+
92+
.. code-block:: c
93+
94+
// Replace <connection string> with your MongoDB deployment's connection string.
95+
const char *uri_string = "<connection string>";
96+
mongoc_uri_t *uri;
97+
mongoc_client_t *client;
98+
mongoc_server_api_t *api;
99+
bson_error_t error;
100+
101+
mongoc_init ();
102+
103+
uri = mongoc_uri_new_with_error (uri_string, &error);
104+
client = mongoc_client_new_from_uri (uri);
105+
106+
// Set the version of the Versioned API on the client.
107+
api = mongoc_server_api_new (MONGOC_SERVER_API_V1);
108+
mongoc_client_set_server_api (client, api, &error);
109+
80110
Connect to ``localhost``
81111
------------------------
82112

source/csharp.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Connect to MongoDB Atlas
5959

6060
using MongoDB.Bson;
6161
using MongoDB.Driver;
62-
// ...
62+
63+
// Replace the uri string with your MongoDB deployment's connection string.
6364
var client = new MongoClient(
6465
"mongodb+srv://<username>:<password>@<cluster-address>/test?w=majority"
6566
);
@@ -70,6 +71,26 @@ Connect to MongoDB Atlas
7071
See `Connecting <https://mongodb.github.io/mongo-csharp-driver/2.12/reference/driver/connecting/>`__
7172
for more information.
7273

74+
Versioned API
75+
-------------
76+
77+
You can use the `Versioned API
78+
<https://docs.mongodb.com/v5.0/reference/versioned-api/>`__ feature
79+
starting with MongoDB Server version 5.0 and C#/.NET Driver version 2.13. When
80+
you use the Versioned API feature, you can update your driver or server
81+
without worrying about backward compatibility issues with any commands
82+
covered by the Versioned API. To use this feature, construct a MongoDB
83+
client instance, specifying a version of the Versioned API:
84+
85+
.. code-block:: csharp
86+
87+
// Replace <connection string> with your MongoDB deployment's connection string.
88+
var settings = MongoClientSettings.FromConnectionString("<connection string>");
89+
90+
// Set the version of the Versioned API on the client.
91+
settings.ServerApi = new ServerApi(ServerApiVersion.V1);
92+
var client = new MongoClient(settings);
93+
7394
Connect to ``localhost``
7495
------------------------
7596

source/go.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ Connect to MongoDB Atlas
5858
See `Usage <https://github.com/mongodb/mongo-go-driver#usage>`__
5959
for more detail.
6060

61+
Versioned API
62+
-------------
63+
64+
You can use the `Versioned API
65+
<https://docs.mongodb.com/v5.0/reference/versioned-api/>`__ feature
66+
starting with MongoDB Server version 5.0 and Go Driver version 1.6. When
67+
you use the Versioned API feature, you can update your driver or server
68+
without worrying about backward compatibility issues with any commands
69+
covered by the Versioned API. To use this feature, construct a MongoDB
70+
client instance, specifying a version of the Versioned API:
71+
72+
.. code-block:: go
73+
74+
// Replace <connection string> with your MongoDB deployment's connection string.
75+
uri := "<connection string>"
76+
77+
ctx := context.TODO()
78+
79+
// Set the version of the Versioned API on the client.
80+
serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1)
81+
clientOptions := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPIOptions)
82+
83+
client, err := mongo.Connect(ctx, clientOptions)
84+
6185
Connect to ``localhost``
6286
------------------------
6387

0 commit comments

Comments
 (0)