Skip to content

Commit 4dc3bb8

Browse files
authored
Issues/245 (#261)
* (#245) MongoDB Driver, complete.
1 parent 16f8496 commit 4dc3bb8

19 files changed

+886
-156
lines changed

Datasync.Toolkit.sln

+14
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{75F7
6464
EndProject
6565
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Datasync.Server", "samples\datasync-server\src\Sample.Datasync.Server\Sample.Datasync.Server.csproj", "{A9967817-2A2C-4C6D-A133-967A6062E9B3}"
6666
EndProject
67+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Datasync.Server.MongoDB", "src\CommunityToolkit.Datasync.Server.MongoDB\CommunityToolkit.Datasync.Server.MongoDB.csproj", "{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}"
68+
EndProject
69+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Datasync.Server.MongoDB.Test", "tests\CommunityToolkit.Datasync.Server.MongoDB.Test\CommunityToolkit.Datasync.Server.MongoDB.Test.csproj", "{4FC45D20-0BA9-484B-9040-641687659AF6}"
70+
EndProject
6771
Global
6872
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6973
Debug|Any CPU = Debug|Any CPU
@@ -154,6 +158,14 @@ Global
154158
{A9967817-2A2C-4C6D-A133-967A6062E9B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
155159
{A9967817-2A2C-4C6D-A133-967A6062E9B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
156160
{A9967817-2A2C-4C6D-A133-967A6062E9B3}.Release|Any CPU.Build.0 = Release|Any CPU
161+
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
162+
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
163+
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
164+
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}.Release|Any CPU.Build.0 = Release|Any CPU
165+
{4FC45D20-0BA9-484B-9040-641687659AF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
166+
{4FC45D20-0BA9-484B-9040-641687659AF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
167+
{4FC45D20-0BA9-484B-9040-641687659AF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
168+
{4FC45D20-0BA9-484B-9040-641687659AF6}.Release|Any CPU.Build.0 = Release|Any CPU
157169
EndGlobalSection
158170
GlobalSection(SolutionProperties) = preSolution
159171
HideSolutionNode = FALSE
@@ -180,6 +192,8 @@ Global
180192
{D3B72031-D4BD-44D3-973C-2752AB1570F6} = {84AD662A-4B9E-4E64-834D-72529FB7FCE5}
181193
{2889E6B2-9CD1-437C-A43C-98CFAFF68B99} = {D59F1489-5D74-4F52-B78B-88037EAB2838}
182194
{A9967817-2A2C-4C6D-A133-967A6062E9B3} = {75F709FD-8CC2-4558-A802-FE57086167C2}
195+
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9} = {84AD662A-4B9E-4E64-834D-72529FB7FCE5}
196+
{4FC45D20-0BA9-484B-9040-641687659AF6} = {D59F1489-5D74-4F52-B78B-88037EAB2838}
183197
EndGlobalSection
184198
GlobalSection(ExtensibilityGlobals) = postSolution
185199
SolutionGuid = {78A935E9-8F14-448A-BEDF-360FB742F14E}

Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<PackageVersion Include="Microsoft.OData.Core" Version="8.2.3" />
2525
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
2626
<PackageVersion Include="Microsoft.Spatial" Version="8.2.3" />
27+
<PackageVersion Include="MongoDB.Driver" Version="3.1.0" />
2728
<PackageVersion Include="NSubstitute" Version="5.3.0" />
2829
<PackageVersion Include="NSwag.AspNetCore" Version="14.2.0" />
2930
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />

infra/modules/cosmos-mongodb.bicep

+43-150
Original file line numberDiff line numberDiff line change
@@ -1,182 +1,75 @@
11
targetScope = 'resourceGroup'
22

3-
@minLength(1)
4-
@description('The name of the test container to create')
5-
param containerName string = 'Movies'
3+
@secure()
4+
@description('The password for the administrator')
5+
param administratorPassword string
66

7-
@minLength(1)
8-
@description('The name of the test database to create')
9-
param databaseName string = 'unittests'
7+
@description('The username for the administrator')
8+
param administratorUsername string = 'tester'
9+
10+
@description('The list of firewall rules to install')
11+
param firewallRules FirewallRule[] = [
12+
{ startIpAddress: '0.0.0.0', endIpAddress: '0.0.0.0' }
13+
]
1014

1115
@minLength(1)
1216
@description('Primary location for all resources')
1317
param location string = resourceGroup().location
1418

15-
@allowed(['3.2', '3.6', '4.0', '4.2'])
16-
@description('Specifies the MongoDB server version to use.')
17-
param mongoVersion string = '4.2'
18-
1919
@description('The name of the Mongo Server to create.')
2020
param serverName string
2121

2222
@description('The list of tags to apply to all resources.')
2323
param tags object = {}
2424

25-
/*********************************************************************************/
26-
27-
var compositeIndices = [
28-
[
29-
{ path: '/BestPictureWinner', order: 'ascending' }
30-
{ path: '/id', order: 'ascending' }
31-
]
32-
[
33-
{ path: '/BestPictureWinner', order: 'descending' }
34-
{ path: '/id', order: 'ascending' }
35-
]
36-
[
37-
{ path: '/Duration', order: 'ascending' }
38-
{ path: '/id', order: 'ascending' }
39-
]
40-
[
41-
{ path: '/Duration', order: 'descending' }
42-
{ path: '/id', order: 'ascending' }
43-
]
44-
[
45-
{ path: '/Rating', order: 'ascending' }
46-
{ path: '/id', order: 'ascending' }
47-
]
48-
[
49-
{ path: '/Rating', order: 'descending' }
50-
{ path: '/id', order: 'ascending' }
51-
]
52-
[
53-
{ path: '/ReleaseDate', order: 'ascending' }
54-
{ path: '/id', order: 'ascending' }
55-
]
56-
[
57-
{ path: '/ReleaseDate', order: 'descending' }
58-
{ path: '/id', order: 'ascending' }
59-
]
60-
[
61-
{ path: '/Title', order: 'ascending' }
62-
{ path: '/id', order: 'ascending' }
63-
]
64-
[
65-
{ path: '/Title', order: 'descending' }
66-
{ path: '/id', order: 'ascending' }
67-
]
68-
[
69-
{ path: '/UpdatedAt', order: 'ascending' }
70-
{ path: '/id', order: 'ascending' }
71-
]
72-
[
73-
{ path: '/UpdatedAt', order: 'descending' }
74-
{ path: '/id', order: 'ascending' }
75-
]
76-
[
77-
{ path: '/Year', order: 'ascending' }
78-
{ path: '/id', order: 'ascending' }
79-
]
80-
[
81-
{ path: '/Year', order: 'descending' }
82-
{ path: '/id', order: 'ascending' }
83-
]
84-
[
85-
{ path: '/Year', order: 'ascending' }
86-
{ path: '/Title', order: 'ascending' }
87-
{ path: '/id', order: 'ascending' }
88-
]
89-
[
90-
{ path: '/Year', order: 'descending' }
91-
{ path: '/Title', order: 'ascending' }
92-
{ path: '/id', order: 'ascending' }
93-
]
94-
[
95-
{ path: '/Year', order: 'ascending' }
96-
{ path: '/Title', order: 'descending' }
97-
{ path: '/id', order: 'ascending' }
98-
]
99-
[
100-
{ path: '/Year', order: 'descending' }
101-
{ path: '/Title', order: 'descending' }
102-
{ path: '/id', order: 'ascending' }
103-
]
104-
]
25+
@description('The tier to use for compute')
26+
@allowed([ 'Free', 'M10', 'M20', 'M25', 'M30', 'M40', 'M50', 'M60', 'M80', 'M200', 'M200-Autoscale'])
27+
param tier string = 'M10'
10528

10629
/*********************************************************************************/
10730

108-
resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
31+
resource cluster 'Microsoft.DocumentDB/mongoClusters@2024-07-01' = {
10932
name: toLower(serverName)
11033
location: location
111-
kind: 'MongoDB'
11234
tags: tags
11335
properties: {
114-
apiProperties: {
115-
serverVersion: mongoVersion
36+
administrator: {
37+
userName: administratorUsername
38+
password: administratorPassword
11639
}
117-
capabilities: [
118-
{
119-
name: 'DisableRateLimitingResponses'
120-
}
121-
]
122-
consistencyPolicy: {
123-
defaultConsistencyLevel: 'Session'
40+
compute: { tier: tier }
41+
highAvailability: {
42+
targetMode: 'Disabled'
12443
}
125-
databaseAccountOfferType: 'Standard'
126-
disableLocalAuth: false
127-
locations: [
128-
{
129-
locationName: location
130-
isZoneRedundant: false
131-
}
132-
]
133-
}
134-
}
135-
136-
resource database 'Microsoft.DocumentDB/databaseAccounts/mongodbDatabases@2022-05-15' = {
137-
parent: account
138-
name: databaseName
139-
tags: tags
140-
properties: {
141-
resource: {
142-
id: databaseName
143-
}
144-
options: {
145-
throughput: 400
44+
publicNetworkAccess: 'Enabled'
45+
serverVersion: '7.0'
46+
sharding: {
47+
shardCount: 1
14648
}
49+
storage: { sizeGb: 32 }
14750
}
14851
}
14952

150-
resource collection 'Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections@2022-05-15' = {
151-
parent: database
152-
name: containerName
153-
tags: tags
154-
properties: {
155-
resource: {
156-
id: containerName
157-
shardKey: {
158-
_id: 'Hash'
159-
}
160-
indexes: [
161-
{
162-
key: {
163-
keys: [
164-
'_id'
165-
]
166-
}
167-
}
168-
{
169-
key: {
170-
keys: [
171-
'$**'
172-
]
173-
}
174-
}
175-
]
53+
resource mongoFirewallRule 'Microsoft.DocumentDB/mongoClusters/firewallRules@2024-07-01' = [
54+
for (fwRule, index) in firewallRules: {
55+
name: fwRule.?name ?? 'rule-${index}'
56+
parent: cluster
57+
properties: {
58+
startIpAddress: fwRule.startIpAddress
59+
endIpAddress: fwRule.endIpAddress
17660
}
17761
}
178-
}
62+
]
63+
17964
/*********************************************************************************/
18065

18166
#disable-next-line outputs-should-not-contain-secrets
182-
output MONGODB_CONNECTIONSTRING string = account.listConnectionStrings().connectionStrings[1].connectionString
67+
output MONGO_CONNECTIONSTRING string = replace(replace(cluster.listConnectionStrings().connectionStrings[0].connectionString, '<user>', administratorUsername), '<password>', administratorPassword)
68+
69+
/*********************************************************************************/
70+
71+
type FirewallRule = {
72+
name: string?
73+
startIpAddress: string
74+
endIpAddress: string
75+
}

infra/resources.bicep

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ module mongodb './modules/cosmos-mongodb.bicep' = {
110110
params: {
111111
location: location
112112
tags: tags
113-
databaseName: testDatabaseName
114-
containerName: cosmosContainerName
115113
serverName: mongoServerName
114+
administratorPassword: sqlAdminPassword
115+
administratorUsername: sqlAdminUsername
116116
}
117117
}
118118

@@ -148,7 +148,7 @@ module app_service './modules/appservice.bicep' = {
148148

149149
output AZSQL_CONNECTIONSTRING string = azuresql.outputs.AZSQL_CONNECTIONSTRING
150150
output COSMOS_CONNECTIONSTRING string = cosmos.outputs.COSMOS_CONNECTIONSTRING
151-
output MONGO_CONNECTIONSTRING string = mongodb.outputs.MONGODB_CONNECTIONSTRING
151+
output MONGO_CONNECTIONSTRING string = mongodb.outputs.MONGO_CONNECTIONSTRING
152152
output MONGOACI_CONNECTIONSTRING string = mongoaci.outputs.MONGO_CONNECTIONSTRING
153153
output MYSQL_CONNECTIONSTRING string = mysql.outputs.MYSQL_CONNECTIONSTRING
154154
output PGSQL_CONNECTIONSTRING string = pgsql.outputs.PGSQL_CONNECTIONSTRING
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Description>A repository for the server-side of the Datasync Toolkit that uses MongoDB for storage.</Description>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<InternalsVisibleTo Include="CommunityToolkit.Datasync.Server.Test" />
8+
<InternalsVisibleTo Include="CommunityToolkit.Datasync.Server.MongoDB.Test" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="MongoDB.Driver" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\CommunityToolkit.Datasync.Server.Abstractions\CommunityToolkit.Datasync.Server.Abstractions.csproj" />
17+
</ItemGroup>
18+
</Project>

0 commit comments

Comments
 (0)