Posts

Showing posts from 2021

Sample code to write custom query in reactive mongo

 This is a sample code snippet to demostrate how to write a custom aggregation with spring data reactive mongo. Here are the sample collection structures: Collection: UserData {    "userId":"123456",    "profilePhotoAssetId":"abcd1234" } Collection: Comment {    "authorId":"123456",    "body":"This is a sample comment",    "userPhotoId": null } userPhotoId is a transient field. It'll be set from the aggregation result. I want to get all comments and inside the comment, I want the profilePhotoAssetId from UserData in the userPhotoId field.  For the above example, the sample output should be: {    "authorId":"123456",    "body":"This is a sample comment",    "userPhotoId":"abcd1234" } What are the steps? 1. First step is to write a lookup operation that'll join the two collection based on comment.authorId and userData.userId. After

Use Postgresql from docker

To me - it's always painful to install and configure Postgresql on local machine. As a developer, it kills much time. Another problem is to manage a list of servers when I've to work with multiple postgres version at the same time. It's better to use Docker to setup database rather than manually installing the DB server. It's super easy to install any database version with just a few steps. In this post I'm going to note down the steps I've followed to install Postgresql 9 inside a docker container. Also I'll import from an existing database to this one.   Step one: Install docker There are plenty of tutorials on this so I'm skipping it. At the end of this step you should be able to run the docker command from terminal. If you are new to docker, I'll recommend to play with it a bit so that you are familiar with the keywords: container, image, docker hub etc.   Step two: Pull the docker image We need to pull the image from docker hub to our local mach