Skip to content

Commit

Permalink
Issues/245 (#261)
Browse files Browse the repository at this point in the history
* (#245) MongoDB Driver, complete.
  • Loading branch information
adrianhall authored Feb 6, 2025
1 parent 16f8496 commit 4dc3bb8
Show file tree
Hide file tree
Showing 19 changed files with 886 additions and 156 deletions.
14 changes: 14 additions & 0 deletions Datasync.Toolkit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{75F7
EndProject
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}"
EndProject
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}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -154,6 +158,14 @@ Global
{A9967817-2A2C-4C6D-A133-967A6062E9B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9967817-2A2C-4C6D-A133-967A6062E9B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9967817-2A2C-4C6D-A133-967A6062E9B3}.Release|Any CPU.Build.0 = Release|Any CPU
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9}.Release|Any CPU.Build.0 = Release|Any CPU
{4FC45D20-0BA9-484B-9040-641687659AF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FC45D20-0BA9-484B-9040-641687659AF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FC45D20-0BA9-484B-9040-641687659AF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FC45D20-0BA9-484B-9040-641687659AF6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -180,6 +192,8 @@ Global
{D3B72031-D4BD-44D3-973C-2752AB1570F6} = {84AD662A-4B9E-4E64-834D-72529FB7FCE5}
{2889E6B2-9CD1-437C-A43C-98CFAFF68B99} = {D59F1489-5D74-4F52-B78B-88037EAB2838}
{A9967817-2A2C-4C6D-A133-967A6062E9B3} = {75F709FD-8CC2-4558-A802-FE57086167C2}
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9} = {84AD662A-4B9E-4E64-834D-72529FB7FCE5}
{4FC45D20-0BA9-484B-9040-641687659AF6} = {D59F1489-5D74-4F52-B78B-88037EAB2838}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {78A935E9-8F14-448A-BEDF-360FB742F14E}
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageVersion Include="Microsoft.OData.Core" Version="8.2.3" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.Spatial" Version="8.2.3" />
<PackageVersion Include="MongoDB.Driver" Version="3.1.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSwag.AspNetCore" Version="14.2.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
Expand Down
193 changes: 43 additions & 150 deletions infra/modules/cosmos-mongodb.bicep
Original file line number Diff line number Diff line change
@@ -1,182 +1,75 @@
targetScope = 'resourceGroup'

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

@minLength(1)
@description('The name of the test database to create')
param databaseName string = 'unittests'
@description('The username for the administrator')
param administratorUsername string = 'tester'

@description('The list of firewall rules to install')
param firewallRules FirewallRule[] = [
{ startIpAddress: '0.0.0.0', endIpAddress: '0.0.0.0' }
]

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

@allowed(['3.2', '3.6', '4.0', '4.2'])
@description('Specifies the MongoDB server version to use.')
param mongoVersion string = '4.2'

@description('The name of the Mongo Server to create.')
param serverName string

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

/*********************************************************************************/

var compositeIndices = [
[
{ path: '/BestPictureWinner', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/BestPictureWinner', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Duration', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Duration', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Rating', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Rating', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/ReleaseDate', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/ReleaseDate', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Title', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Title', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/UpdatedAt', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/UpdatedAt', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'ascending' }
{ path: '/Title', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'descending' }
{ path: '/Title', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'ascending' }
{ path: '/Title', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'descending' }
{ path: '/Title', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
]
@description('The tier to use for compute')
@allowed([ 'Free', 'M10', 'M20', 'M25', 'M30', 'M40', 'M50', 'M60', 'M80', 'M200', 'M200-Autoscale'])
param tier string = 'M10'

/*********************************************************************************/

resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
resource cluster 'Microsoft.DocumentDB/mongoClusters@2024-07-01' = {
name: toLower(serverName)
location: location
kind: 'MongoDB'
tags: tags
properties: {
apiProperties: {
serverVersion: mongoVersion
administrator: {
userName: administratorUsername
password: administratorPassword
}
capabilities: [
{
name: 'DisableRateLimitingResponses'
}
]
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
compute: { tier: tier }
highAvailability: {
targetMode: 'Disabled'
}
databaseAccountOfferType: 'Standard'
disableLocalAuth: false
locations: [
{
locationName: location
isZoneRedundant: false
}
]
}
}

resource database 'Microsoft.DocumentDB/databaseAccounts/mongodbDatabases@2022-05-15' = {
parent: account
name: databaseName
tags: tags
properties: {
resource: {
id: databaseName
}
options: {
throughput: 400
publicNetworkAccess: 'Enabled'
serverVersion: '7.0'
sharding: {
shardCount: 1
}
storage: { sizeGb: 32 }
}
}

resource collection 'Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections@2022-05-15' = {
parent: database
name: containerName
tags: tags
properties: {
resource: {
id: containerName
shardKey: {
_id: 'Hash'
}
indexes: [
{
key: {
keys: [
'_id'
]
}
}
{
key: {
keys: [
'$**'
]
}
}
]
resource mongoFirewallRule 'Microsoft.DocumentDB/mongoClusters/firewallRules@2024-07-01' = [
for (fwRule, index) in firewallRules: {
name: fwRule.?name ?? 'rule-${index}'
parent: cluster
properties: {
startIpAddress: fwRule.startIpAddress
endIpAddress: fwRule.endIpAddress
}
}
}
]

/*********************************************************************************/

#disable-next-line outputs-should-not-contain-secrets
output MONGODB_CONNECTIONSTRING string = account.listConnectionStrings().connectionStrings[1].connectionString
output MONGO_CONNECTIONSTRING string = replace(replace(cluster.listConnectionStrings().connectionStrings[0].connectionString, '<user>', administratorUsername), '<password>', administratorPassword)

/*********************************************************************************/

type FirewallRule = {
name: string?
startIpAddress: string
endIpAddress: string
}
6 changes: 3 additions & 3 deletions infra/resources.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ module mongodb './modules/cosmos-mongodb.bicep' = {
params: {
location: location
tags: tags
databaseName: testDatabaseName
containerName: cosmosContainerName
serverName: mongoServerName
administratorPassword: sqlAdminPassword
administratorUsername: sqlAdminUsername
}
}

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

output AZSQL_CONNECTIONSTRING string = azuresql.outputs.AZSQL_CONNECTIONSTRING
output COSMOS_CONNECTIONSTRING string = cosmos.outputs.COSMOS_CONNECTIONSTRING
output MONGO_CONNECTIONSTRING string = mongodb.outputs.MONGODB_CONNECTIONSTRING
output MONGO_CONNECTIONSTRING string = mongodb.outputs.MONGO_CONNECTIONSTRING
output MONGOACI_CONNECTIONSTRING string = mongoaci.outputs.MONGO_CONNECTIONSTRING
output MYSQL_CONNECTIONSTRING string = mysql.outputs.MYSQL_CONNECTIONSTRING
output PGSQL_CONNECTIONSTRING string = pgsql.outputs.PGSQL_CONNECTIONSTRING
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>A repository for the server-side of the Datasync Toolkit that uses MongoDB for storage.</Description>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="CommunityToolkit.Datasync.Server.Test" />
<InternalsVisibleTo Include="CommunityToolkit.Datasync.Server.MongoDB.Test" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Datasync.Server.Abstractions\CommunityToolkit.Datasync.Server.Abstractions.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit 4dc3bb8

Please sign in to comment.