Skip to content

Commit c8e76e5

Browse files
CSHARP-3658: Versioned API Connection Examples for Docs (#533)
1 parent 1c93528 commit c8e76e5

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* Copyright 2021-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
namespace MongoDB.Driver.Examples
17+
{
18+
public class VersionedApiExamples
19+
{
20+
public void ConfigureServerApi()
21+
{
22+
// Start Versioned API Example 1
23+
var connectionString = "mongodb://localhost";
24+
var serverApi = new ServerApi(ServerApiVersion.V1);
25+
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
26+
mongoClientSettings.ServerApi = serverApi;
27+
var mongoClient = new MongoClient(mongoClientSettings);
28+
// End Versioned API Example 1
29+
}
30+
31+
public void ConfigureServerApiStrict()
32+
{
33+
// Start Versioned API Example 2
34+
var connectionString = "mongodb://localhost";
35+
var serverApi = new ServerApi(ServerApiVersion.V1, strict: true);
36+
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
37+
mongoClientSettings.ServerApi = serverApi;
38+
var mongoClient = new MongoClient(mongoClientSettings);
39+
// End Versioned API Example 2
40+
}
41+
42+
public void ConfigureServerApiNonStrict()
43+
{
44+
// Start Versioned API Example 3
45+
var connectionString = "mongodb://localhost";
46+
var serverApi = new ServerApi(ServerApiVersion.V1, strict: false);
47+
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
48+
mongoClientSettings.ServerApi = serverApi;
49+
var mongoClient = new MongoClient(mongoClientSettings);
50+
// End Versioned API Example 3
51+
}
52+
53+
public void ConfigureServerApiDeprecationErrors()
54+
{
55+
// Start Versioned API Example 4
56+
var connectionString = "mongodb://localhost";
57+
var serverApi = new ServerApi(ServerApiVersion.V1, deprecationErrors: true);
58+
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
59+
mongoClientSettings.ServerApi = serverApi;
60+
var mongoClient = new MongoClient(mongoClientSettings);
61+
// End Versioned API Example 4
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)