-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
250 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,53 @@ | ||
const { MongoClient } = require("mongodb"); | ||
|
||
const uri = process.env.MONGODB_URI; | ||
const client = new MongoClient(uri); | ||
|
||
type Movie = { | ||
title: string; | ||
}; | ||
|
||
async function addFilm(title: string) { | ||
try { | ||
const database = client.db('sample_mflix'); | ||
const movies = database.collection('movies'); | ||
const movie = { title }; | ||
await movies.insertOne(movie); | ||
console.log(`Added film: ${title}`); | ||
} finally { | ||
await client.close(); | ||
} | ||
} | ||
|
||
async function listFilms() { | ||
try { | ||
const database = client.db('sample_mflix'); | ||
const movies = database.collection('movies'); | ||
const moviesList: Movie[] = await movies.find({}).toArray(); | ||
console.log("List of films:"); | ||
moviesList.forEach(movie => { | ||
console.log(movie.title); | ||
}); | ||
} finally { | ||
await client.close(); | ||
} | ||
} | ||
|
||
async function run() { | ||
const command = process.argv[2]; | ||
const arg = process.argv[3]; | ||
|
||
if (command === "add") { | ||
if (!arg) { | ||
console.error("Please provide a film title to add."); | ||
return; | ||
} | ||
await addFilm(arg); | ||
} else if (command === "list") { | ||
await listFilms(); | ||
} else { | ||
console.error("Invalid command. Usage: node mongo.js [add film-title | list]"); | ||
} | ||
} | ||
|
||
run().catch(console.dir); |
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,27 @@ | ||
resource "azurerm_resource_group" "rg" { | ||
location = var.resource_group_location | ||
name = var.resource_group_name | ||
} | ||
|
||
resource "azurerm_user_assigned_identity" "identity" { | ||
resource_group_name = azurerm_resource_group.rg.name | ||
location = azurerm_resource_group.rg.location | ||
name = "tofu-mongo-bespinian-labs-identity" | ||
} | ||
|
||
resource "azurerm_cosmosdb_account" "cosdb" { | ||
name = "bespinian-resource" | ||
location = azurerm_resource_group.rg.location | ||
resource_group_name = azurerm_resource_group.rg.name | ||
offer_type = "Standard" | ||
kind = "MongoDB" | ||
|
||
geo_location { | ||
location = azurerm_resource_group.rg.location | ||
failover_priority = 0 | ||
} | ||
|
||
consistency_policy { | ||
consistency_level = "Eventual" | ||
} | ||
} |
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,4 @@ | ||
output "cosmosdb_connectionstrings" { | ||
value = azurerm_cosmosdb_account.cosdb.connection_strings | ||
sensitive = true | ||
} |
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,14 @@ | ||
terraform { | ||
required_version = ">=0.12" | ||
|
||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "~>2.0" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} |
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,11 @@ | ||
variable "resource_group_location" { | ||
type = string | ||
default = "westeurope" | ||
description = "Location of the resource group." | ||
} | ||
|
||
variable "resource_group_name" { | ||
type = string | ||
default = "tofu-mongo-bespinian-labs" | ||
description = "Name of the resource group." | ||
} |