Skip to content
This repository has been archived by the owner on Aug 16, 2020. It is now read-only.

Latest commit

 

History

History
71 lines (56 loc) · 2.59 KB

README.md

File metadata and controls

71 lines (56 loc) · 2.59 KB

Setup Instructions for connecting MongoDB, the C# driver, and GCP

This guide will run you through setting up MongoDB on gcloud, and connect to the database instance remotely.


Resources

MongoDB on Compute Engine

MongoDB Compute Engine Tutorial

C# MongoDB Examples


GCP setup

From the first link, 'MongoDB on Compute Engine'...

  1. Click 'Launch on Compute Engine'
    • It should bring you to a page with 'New MongoDB deployment'
  2. Zone: us-west1-x

Servers Tier

  1. Instances Count: 2
  2. Machine type: small (1 shared vCPU)
  3. Data disk size in GB (20)

Arbiters Tier

  1. Instances Count: 1
  2. Machine type: small (1 shared vCPU)`

Wait for it to deploy... (You should get an e-mail when it is complete)

  1. SSH connect to any node and run mongo; rs.status() to check the replica staus
  2. Power off all machines when you are done

Manage the GCP firewall for external access to the db

  1. In GCP, expand the hanburger menu
  2. Under Networking, VPC network > Firewall rules
  3. Create firewall rule
  4. Enter some name, like allow-psu
  5. Direction of traffic > ingress
  6. Targets > All instances in the network
  7. Source filter > IP range
  8. For PSU, enter 131.252.0.0/16 (16 is the CIDR subnet mask for 255.255.0.0, 24 is for 255.255.255.0)
  9. Protocols and ports > Specified protocols and ports
  10. In the box, enter: tcp:27017
  11. Save

C# Driver setup via Visual Studios

  1. Download Visual Studios
  2. Create a new Project; Console App (.NET Core)
  3. Once created, go to Project > Manage NuGet packages
  4. Install MongoDB.Driver and MongoDB.Bson
  5. Install CsvHelper
  6. Copy the code from Program.cs
  7. Change the MongoClient connection string to use your primary node's external IP
    • Must have a majority of the instances running, so that they can hold an election & elect a primary
    • I just run one data-bearing instance and the arbiter node
    • External IP is on Compute Engine > VM Instances
    • You can verify if the instance is primary or secondary via gcloud ssh
  8. Be sure to copy the listings.csv file to the project folder
    • I created a 'data' folder in the project root dir
    • The program executes from rootdir/bin/Debug/netcoreapp3.0
    • At the very least, be sure to change 'src' var to match the .csv file for listings
  9. Run