Coder Social home page Coder Social logo

mongocs's Introduction

MongoDB Changestream demo

This poc project can be used to demonstrate the change stream concept and how it can be used to create an audit trail if needed. The application is designed to only receive updates of customers with the birth month specified in the property watch.cursor.month. It will default to January if no month is provided

Tech

  • Java 1.8
  • Mongo DB 4.2.3
  • Gradle 5.6.4

Installation

From the root of the project run the following commands:

mkdir -pv data/db
mongod --dbpath ./data/db --replSet "rs"

if you get address already in use error then run the following commands in a new shell

mongo
use admin
db.shutdownServer()

Then run the previous commands before running the following.

Then in a separate shell tab, run:

mongo

After the rs:PRIMARY> prompt (or just > in the first run) appears, run:

rs.initiate()

For the first run the output will be something like

{
	"info2" : "no configuration specified. Using a default configuration for the set",
	"me" : "localhost:27017",
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1586447207, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1586447207, 1)
}

For subsequent runs it may give an error like below which can be ignored

{
	"operationTime" : Timestamp(1586447350, 1),
	"ok" : 0,
	"errmsg" : "already initialized",
	"code" : 23,
	"codeName" : "AlreadyInitialized",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1586447350, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}

Open a new terminal window and navigate to the root of the project. Then run

mongo src/main/resources/createCustomers.js

Completing these steps will start the mongo db and a steady stream of data getting inserted in the database test and in collection customers with random first and last names and a random birth month. Once this setup is done start the spring boot app with the following command

gradle bootRun

The app will now start receiving the updates of users with the birthday month as specified. The createCustomers.js file is only inserting records, to see an update a query like below can be executed in mongo shell

db.customers.update({"firstName":"fname3195"},{$set: {"lastName":"uofname2376"}});

mongocs's People

Contributors

mashariqk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.