Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
timjonesdev / initial_data.js
Created August 20, 2019 21:55
Initial Data Model for Reactive Mongo Example
db.teams.insert(
[
{
"_id": ObjectId("5d0c18c190d2b33ae629aaa7"),
"name": "HingleMcCringleberry",
"players": [
{"name": "Nick Chubb", "score": 0},
{"name": "James Conner", "score": 0},
{"name": "Julio Jones", "score": 0},
{"name": "Michael Thomas", "score": 0}
@timjonesdev
timjonesdev / Team.java
Created August 20, 2019 21:54
Team model for Reactive Mongo Example
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.ArrayList;
@timjonesdev
timjonesdev / Player.java
Last active August 20, 2019 21:53
Player Model for Reactive Mongo Example
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@timjonesdev
timjonesdev / Makefile
Last active August 16, 2019 17:51
A one-command start for MongoDB
# this assumes that your docker-compose.yml file is located in ./docker
up-db-local: rebuild-mongo
pushd docker &&\
docker-compose up -d mongo &&\
popd
rebuild-mongo:
pushd docker &&\
docker-compose build mongo-seed &&\
docker-compose up mongo-seed &&\
@timjonesdev
timjonesdev / Dockerfile
Created August 16, 2019 17:27
Mongo Seed Data Example with Docker and Docker Compose
FROM mongo:4.0
COPY init.js /init.js
@timjonesdev
timjonesdev / mongo_changestream_error.sh
Created August 16, 2019 04:25
The error encountered when trying to watch a Change Stream on a MongoDB instance that is not part of a replica set.
com.mongodb.MongoCommandException:
Command failed with error 40573 (Location40573):
'The $changeStream stage is only supported on replica sets' on server localhost:27017.
The full response is:
{
"ok" : 0.0,
"errmsg" : "The $changeStream stage is only supported on replica sets",
"code" : 40573,
"codeName" : "Location40573"
}
@timjonesdev
timjonesdev / MongoDockerfile
Last active November 28, 2019 16:43
A MongoDB Dockerfile which enables a single-node replicaset
FROM mongo:4.0
# files used to initialize the database
COPY ./init-db.d/ /docker-entrypoint-initdb.d
# add this command to a js file in the init directory
# formatted on newlines for better readability
RUN echo "rs.initiate(
{
_id: 'rs0',
@timjonesdev
timjonesdev / MongoFirstDockerfile
Created August 16, 2019 04:19
The first draft of the Mongo Dockerfile
FROM mongo:4.0
# files used to initialize the database
COPY ./init-db.d/ /docker-entrypoint-initdb.d
@timjonesdev
timjonesdev / docker-cleanup.sh
Created June 29, 2019 04:42
A cleanup script for docker resources, if you don't have `docker system prune` available. WARNING: This will delete all containers, images, and volumes.
#!/usr/bin/env bash
echo "Running docker cleanup script"
echo "Stopping all containers"
docker stop $(docker ps -a -q) # Stop all containers
echo "Removing stopped containers"
docker rm $(docker ps -a -q) # Remove all stopped containers
@timjonesdev
timjonesdev / my-lib-good.module.ts
Last active June 27, 2019 20:24
The correct way to import modules in an Angular library
import {NgModule} from '@angular/core';
import {MyLibComponent} from './my-lib.component';
import {NavigationModule} from "./navigation/navigation.module"; // <-- lengthened
import {FormModule} from "./form/form.module"; // <-- lengthened
@NgModule({
declarations: [MyLibComponent],
imports: [NavigationModule, FormModule],
exports: [NavigationModule, FormModule]
})